Technical skill

Kubernetes

Keep an application running on a group of computers

Suppose a web application should keep two copies running and replace a copy when it fails. Kubernetes manages applications packaged as containers across a group of cooperating computers called a cluster. A container packages an application so it runs in a predictable environment. You describe the state you want, such as two copies of a web program, and Kubernetes works to make the cluster match that description. It coordinates the work; the application inside a container can still have bugs or lose access to an outside service.

A small practice example asks for two copies of an Nginx web server. A Deployment is a Kubernetes object that tells the system how many copies of an application to keep running. The example is written in YAML, a text format for structured settings; the file is called a manifest:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: web-demo
spec:
  replicas: 2
  selector:
    matchLabels:
      app: web-demo
  template:
    metadata:
      labels:
        app: web-demo
    spec:
      containers:
        - name: web
          image: nginx:alpine
          ports:
            - containerPort: 80

Save the file as web-demo.yaml. Before applying it, check which cluster the command will contact, then create and inspect the Deployment:

kubectl config current-context
kubectl apply -f web-demo.yaml
kubectl get deployment web-demo
kubectl get pods -l app=web-demo
kubectl describe deployment web-demo

The manifest creates a Deployment only. A separate Service object is needed if other workloads should reach the web copies through a stable network name or address. Check kubectl config current-context before applying changes because kubectl sends requests to the cluster selected by the active context.

The pieces that carry out the request

The Kubernetes API server receives requests. Controllers compare the requested state with the current state and try to reconcile differences. The scheduler chooses a suitable worker node, one of the computers in the cluster, for each Pod. Each node runs a kubelet, which checks its assigned Pods, and a container runtime, which starts the containers. A small learning cluster can place several components on one computer; larger clusters spread them out.

A Pod is the smallest unit Kubernetes deploys. It holds one or more containers that run together and share a network namespace; they can also share configured storage. Containers in a Pod use the same IP address and port space, so they can reach one another through localhost. Pods can be replaced, so another resource usually manages them.

A Deployment is commonly used for a stateless application, one that does not depend on data kept only on a particular Pod, and says how many copies to keep. Its controller manages ReplicaSets, which maintain the requested number of Pods. During a rollout, the Deployment controller creates and adjusts ReplicaSets. A Service selects Pods by labels and gives them a stable network name or address while their own addresses change; it routes traffic to the selected Pod endpoints.

Check more than the saved request

An accepted apply means the API stored the object. Controllers and node agents still need to create Pods, pull the image, and pass readiness checks. If fewer Pods become available than requested, inspect events, readiness, and logs. Labels must match the selectors a ReplicaSet or Service uses.

Controllers replace Pods according to their policies, but application code can still be wrong and an outside dependency can be unavailable. Persistent data needs a suitable volume and recovery plan. Resource requests, probes, credentials, network policies, and rollout settings also affect behavior. Apply one Deployment, wait until its copies are ready, then add a Service and inspect its endpoints. Test scaling and a rollout separately so you can see which controller changes the cluster.

Interactive exercises

Materials

Skillsets
Skillset Linux administrator preview
image descriptionLinux administrator
by Infinite Education
3080 users
Skillset Web Backend Developer preview
image descriptionWeb Backend Developer
by Infinite Education
2092 users
Skillset Devops preview
image descriptionDevops
by Ajay Kumar
2004 users
Skillset PostgreSQL DBA preview
image descriptionPostgreSQL DBA
by Artem Naumenko (fb)
1630 users
Skillset DevOps engineer preview
image descriptionDevOps engineer
by Infinite Education
1211 users
Skillset DevOps preview
image descriptionDevOps
by Federico Cordone
3 users
Skillset Devops preview
image descriptionDevops
by Dio
3 users
Do you know that ...?
Any useful or interesting facts about the skill. Any peace of information would be useful