Kubernetes Objects

An object is a persistent entity in the Kubernetes system. Each object represents a part of the state of our cluster, and all of them together represent the whole desired state.

Objects can describe:

  • What containerized applications are running (and on which nodes)
  • The resources available to those applications
  • The policies around how those applications behave (e.g. restart policies, upgrades, fault tolerance etc.)

An object is a "record of intent"— it is our way of declaring the cluster's desired state.

  • once you create the object, the Kubernetes system will constantly work to ensure that object exists.

To create, read or modify an object, we interact with the Kubernetes API.

  • If we are using Kubectl, calls to the API will be made for us.

Almost every object should take this shape:

{
  spec: {
    // desired state
  },
  status: // current state of the object, managed by the control plane
}

Even though we can create services by running kubectl expose, we should typically follow a documented approach by using YAML files.

Fields

selector

selector:
  matchLabels:
    app: hellok8s

What we are doing in this field is telling Kubernetes that this object is managing all the pods that have a label called app with the value hellok8s. This is what links our object to pods.

  • Labels are simply key-value pairs that you define for your pods, and that’s what is used to find all the pods that a Deployment needs to look after.

Children
  1. Configmap
  2. Deployment
  3. HorizontalPodAutoscaler
  4. Kubernetes Ingress
  5. Kubernetes Pod
  6. Kubernetes Service
  7. Namespace
  8. PodDisruptionBudget
  9. Service Accou
  10. Volume

Backlinks