Sobes.tech
Middle

What happens when creating a Deployment entity in the system?

sobes.tech AI

Answer from AI

When creating a Deployment in Kubernetes, the following occurs:

  1. The Deployment controller detects the appearance of a new Deployment entity.
  2. Upon receiving the Deployment definition, the controller creates or updates the corresponding ReplicaSet. The ReplicaSet is responsible for maintaining the specified number of pod replicas.
  3. The ReplicaSet, in turn, creates the pods specified in the Template. The pod template is taken from the Deployment specification (field spec.template). This template defines the container image, ports, volume mounts, and other pod parameters.
  4. The pods are handed over to the scheduler.
  5. The scheduler selects suitable cluster nodes to run the pods based on constraints (resources, affinity/anti-affinity, etc.).
  6. The kubelet on the selected nodes receives instructions from the kube-apiserver and starts containers inside the pods.
  7. The kubelet reports the status of the pods back to the kube-apiserver.
  8. The Deployment and ReplicaSet controllers continuously monitor the state of the pods, ensuring the desired number of replicas and handling failures or changes in the Deployment.

Example of a Deployment specification:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment # Deployment name
spec:
  replicas: 3 # Desired number of pod replicas
  selector:
    matchLabels:
      app: nginx # Selector to find pods managed by this deployment
  template:
    metadata:
      labels:
        app: nginx # Labels for the created pods
    spec:
      containers:
      - name: nginx # Container name
        image: nginx:1.14.2 # Container image
        ports:
        - containerPort: 80 # Container port