logo

Kubernetes - Objects

Last Updated: 2023-08-27

Get a list of object types

Each K8s version may have a different set of supported object types, check yours by:

$ kubectl version
$ kubectl api-versions
$ kubectl api-resources

List all objects grouped by API versions:

a=$(kubectl api-versions) ; for n in $a ; do echo ; echo "apiVersion: $n" ; kubectl api-resources --api-group="${n%/*}" ; done

Object vs kind vs resources

  • A Kubernetes object is a persistent entities in the Kubernetes system.
  • A Kubernetes resource is an endpoint in the Kubernetes API that stores a collection of API objects of a certain kind; for example, the built-in pods resource contains a collection of Pod objects.

apiVersion

Format: $GROUP_NAME/$VERSION, for example, apiVersion: batch/v1.

metadata

annotations, labels, taints and finalizers are all list of strings in metadata.

https://kubernetes.io/docs/reference/labels-annotations-taints/

finalizers

If metadata.finalizers is not empty, when you attempt to delete the resource, it will not be delete right away, but will be in the Terminating status. Only when finalizers is emptied by some reconcilers (or by manually modification) will the resource be deleted.

E.g. these finalizers are used to prevent accidental deletion of PV and PVC:

kubernetes.io/pv-protection
kubernetes.io/pvc-protection

Built-in Objects

  • App: Pod, Deployment, DaemonSet, StatefulSet
  • Storage: PersistentVolume, PersistentVolumeClaim, StorageClass

EndpointSlice

Services will create Endpoints, one for each healthy pod. (I.e. each Endpoint is a ip:port pointing to the Pod that is part of this Service.)

EndpointSlice replaces Endpoints.

Relations:

Service <= (ownerReferences) <= EndpointSlice => (targetRef) => Pods

Deployment

A deployment is responsible for keeping a set of pods running.

Gateway

Incoming requests: Gateway -> Service (of type LoadBalancer) -> Deployment -> ReplicaSet -> Pod.

Istio defines a Gateway but it is migrating to Kubernetes' Gateway.

Gateway configuration resources allow external traffic to enter the Istio service mesh and make the traffic management and policy features of Istio available for edge services.

CronJob

cronjob controller will create jobs.

Application

applications, app.k8s.io/v1beta1

(https://github.com/kubernetes-sigs/application)

Cluster

A "Cluster" is conceptually the collection of all the control plane and worker node components.

k8s has a built-in Cluster object in cluster-api sig: config/crd/bases/cluster.x-k8s.io_clusters.yaml. (https://github.com/kubernetes-sigs/cluster-api/)

Some projects built upon k8s may also have a Cluster object, e.g. Anthos Bare Metal.

Lease

apiVersion: coordination.k8s.io/v1
kind: Lease

Node lease: Each Node has an associated Lease object in the kube-node-lease namespace.

Under the hood, every kubelet heartbeat is an update request to this Lease object, updating the spec.renewTime field for the Lease. The Kubernetes control plane uses the time stamp of this field to determine the availability of this Node.

API Server lease: provides a mechanism for clients to discover how many instances of kube-apiserver are operating the Kubernetes control plane.

namespace: kube-system
name: apiserver-<sha256-hash>