Creating a Kubernetes Deployment that supports rolling updates and rollbacks of application containers

Kwame Kilpatrick is a RHEL Sysadmin at Google. He is working on eventually obtaining several Kubternetes certifications. His motivation: once he has completed all Kubernetes certification programs, he will take over as Google's Kubernetes Training Director. His setup:

  • His server is RHEL_Server_875
  • His username: kwame.kilpatrick@google.com
  • His professional preference: a competent Linux Engineer NEVER runs Linux commands as the root user.
  • His learning objective: Demonstrate the ability to create a Kubernetes Deployment that supports rolling updates and rollbacks of application containers.

Please generate and explain all of the commands that he will need to execute on his RHEL System to complete this task.

To complete the task of creating a Kubernetes Deployment that supports rolling updates and rollbacks of application containers, Kwame Kilpatrick, the RHEL Sysadmin at Google, will need to execute a series of commands on his RHEL Server. Here's a step-by-step guide:

  1. Connect to the RHEL server:

    • ssh kwame.kilpatrick@google.com@RHEL_Server_875
  2. Install the necessary software components:
    • sudo yum install -y docker kubectl kubernetes-cni
  3. Start the Docker service:
    • sudo systemctl start docker
  4. Verify the Docker service status:
    • sudo systemctl start docker
  5. Enable the Docker service to start on system boot:
    • sudo systemctl enable docker
  6. Configure Kubernetes and set up the cluster:
    • sudo kubeadm init
    • This command initializes the Kubernetes control plane. After it completes, it will display a command to join other nodes to the cluster. Make note of this command.
  7. Set up the local kubeconfig for the current user:
    • mkdir -p $HOME/.kube
      sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
      sudo chown $(id -u):$(id -g) $HOME/.kube/config
  8. Join additional worker nodes to the cluster (if applicable):

    • # Use the command obtained in step 6 on each worker node
      sudo kubeadm join <MASTER_NODE_IP>:<TOKEN> --token <TOKEN> --discovery-token-ca-cert-hash <CERT_HASH>
  9. Verify the cluster status:
    • kubectl get nodes
    • This command should display the master node and any joined worker nodes.
  10. Create a Kubernetes Deployment manifest file (deployment.yaml) with rolling update and rollback support. An example content for the file:
    • apiVersion: apps/v1
      kind: Deployment
      metadata:
        name: my-deployment
      spec:
        replicas: 3
        selector:
          matchLabels:
            app: my-app
        template:
          metadata:
            labels:
              app: my-app
          spec:
            containers:
              - name: my-app-container
                image: my-app:v1
                ports:
                  - containerPort: 8080
                resources:
                  limits:
                    cpu: "1"
                    memory: "1Gi"
                readinessProbe:
                  httpGet:
                    path: /health
                    port: 8080
                  initialDelaySeconds: 10
                  periodSeconds: 5
                livenessProbe:
                  httpGet:
                    path: /health
                    port: 8080
                  initialDelaySeconds: 30
                  periodSeconds: 10
        strategy:
          rollingUpdate:
            maxSurge: 1
            maxUnavailable: 1
          type: RollingUpdate
    • Adjust the values as per your application requirements.
  11. Apply the deployment to the Kubernetes cluster:
    • kubectl apply -f deployment.yaml
  12. Monitor the deployment status:
    • kubectl get deployments
      kubectl get pods
    • These commands will display the status of the deployment and the created pods.
  13. Perform a rolling update of the application:
    • kubectl set image deployment/my-deployment my-app-container=my-app:v2
    • This command updates the image of the deployment to my-app:v2. Kubernetes will automatically perform a rolling update, replacing the pods with the new version while ensuring availability.
  14. Monitor the rolling update progress:
    • kubectl rollout status deployment/my-deployment
    • This command displays the status of the rolling update process.
  15. Perform a rollback of the application:
    • kubectl rollout undo deployment/my-deployment
    • This command reverts the deployment to the previous version, effectively rolling back the changes.

These commands will help Kwame Kilpatrick execute the necessary steps to create a Kubernetes Deployment supporting rolling updates and rollbacks of application containers on his RHEL server.

You should also read: