Flashcards
Aron Midgård - APIS and Access
Cards in this deck (21)
- 1API AccessKubernetes has a powerful REST-based API. The entire architecture is API-driven. Knowing where to find resource endpoints and understanding how the API changes between versions can be important to ongoing administrative tasks, as there is much ongoing change and growth. Starting with v1.16 deprecated objects are no longer honored by the API server.
As we learned in the Kubernetes Architecture chapter, the main agent for communication between cluster agents and from outside the cluster is the kube-apiserver. A curl query to the agent will expose the current API groups. Groups may have multiple versions, which evolve independently of other groups, and follow a domain-name format with several names reserved, such as single-word domains, the empty group, and any name ending in .k8s.io. - 2RESTfulkubectl makes API calls on your behalf, responding to typical HTTP verbs (GET, POST, DELETE). You can also make calls externally, using curl or other program. With the appropriate certificates and keys, you can make requests, or pass JSON files to make configuration changes.
$ curl --cert userbob.pem --key userBob-key.pem \
--cacert /path/to/ca.pem \
https://k8sServer:6443/api/v1/pods
The ability to impersonate other users or groups, subject to RBAC configuration, allows a manual override authentication. This can be helpful for debugging authorization policies of other users. - 3Checking AccessThere are currently three APIs which can be applied to set who and what can be queried:
SelfSubjectAccessReview
Access review for any user, helpful for delegating to others.
LocalSubjectAccessReview
Review is restricted to a specific namespace.
SelfSubjectRulesReview
A review which shows allowed actions for a user within a particular namespace.
The use of reconcile allows a check of authorization necessary to create an object from a file. No output indicates the creation would be allowed. - 4Optimistic Concurrencyhe default serialization for API calls must be JSON. There is an effort to use Google's protobuf serialization, but this remains experimental. While we may work with files in a YAML format, they are converted to and from JSON.
Kubernetes uses the resourceVersion value to determine API updates and implement optimistic concurrency. In other words, an object is not locked from the time it has been read until the object is written.
Instead, upon an updated call to an object, the resourceVersion is checked, and a 409 CONFLICT is returned, should the number have changed. The resourceVersion is currently backed via the modifiedIndex parameter in the etcd database, and is unique to the namespace, kind, and server. Operations which do not change an object, such as WATCH or GET, do not update this value. - 5Using AnnotationsLabels are used to work with objects or collections of objects; annotations are not.
Instead, annotations allow for metadata to be included with an object that may be helpful outside of the Kubernetes object interaction. Similar to labels, they are key to value maps. They are also able to hold more information, and more human-readable information than labels.
Having this kind of metadata can be used to track information such as a timestamp, pointers to related objects from other ecosystems, or even an email from the developer responsible for that object's creation.
The annotation data could otherwise be held in an exterior database, but that would limit the flexibility of the data. The more this metadata is included, the easier it is to integrate management and deployment tools or shared client libraries.
For example, to annotate only Pods within a namespace, you can overwrite the annotation, and finally delete it:
$ kubectl annotate pods --all description='Production Pods' -n prod
$ kubectl annotate --overwrite pods description="Old Production Pods" -n prod
$ kubectl an - 6~/.kube/configapiVersion
clusters
contexts
current-context
kind
preferences
users - 7(config)apiVersionAs with other objects, this instructs the kube-apiserver where to assign the data.
- 8(config) clustersThis key contains the name of the cluster, as well as where to send the API calls. The certificate-authority-data is passed to authenticate the curl request.
- 9(config) contextsThis is a setting which allows easy access to multiple clusters, possibly as various users, from one configuration file. It can be used to set namespace, user, and cluster.
- 10(config) current-contextThis shows which cluster and user the kubectl command would use. These settings can also be passed on a per-command basis.
- 11(config) kindEvery object within Kubernetes must have this setting; in this case, a declaration of object type Config.
- 12(config) preferencesCurrently not used, this is an optional settings for the kubectl command, such as colorizing output.
- 13(config) usersA nickname associated with client credentials, which can be client key and certificate, username and password, and a token. Token and username/password are mutually exclusive. These can be configured via the kubectl config set-credentials command.
- 14NamespacesThe term namespace is used to reference both the kernel feature and the segregation of API objects by Kubernetes. Both are means to keep resources distinct.
Namespaces, a Linux kernel feature that segregates system resources, are intended to isolate multiple groups and the resources they have access to work with via quotas. Eventually, access control policies will work on namespace boundaries, as well. One could use labels to group resources for administrative reasons.
-default
-kube-node-lease
-kube-public
-kube-system - 15(namespaces) defaultThis is where all the resources are assumed, unless set otherwise.
- 16(namespaces) kube-node-leaseThis is the namespace where worker node lease information is kept.
- 17(namespaces) kube-publicA namespace readable by all, even those not authenticated. General information is often included in this namespace.
- 18(namespaces) kube-systemThis namespace contains infrastructure pods.
- 19working with namespacesWorking with Namespaces
Take a look at the following commands:
$ kubectl get ns
$ kubectl create ns linuxcon
$ kubectl describe ns linuxcon
$ kubectl get ns/linuxcon -o yaml
$ kubectl delete ns/linuxcon
The above commands show how to view, create and delete namespaces. Note that the describe subcommand shows several settings, such as Labels, Annotations, resource quotas, and resource limits, which we will discus later in the course. - 20API Resources with kubectlAll API resources exposed are available via kubectl. To get more information, do kubectl help.
kubectl [command] [type] [Name] [flag] - 21Swagger and OpenAPIThe entire Kubernetes API uses a Swagger specification. This is evolving towards the OpenAPI initiative. It is extremely useful, as it allows, for example, to auto-generate client code. All the stable resources definitions are available on the documentation site.
You can browse some of the API groups via a Swagger UI on the OpenAPI Specification web page.
Information
- Description
- Flashcards on Aron Midgård - APIS and Access, created by Assar Pettersson on 07/05/2020.
- Created by
- Assar Pettersson
- Views
- 4
- Rating