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:
Connect to the RHEL server:
- ssh kwame.kilpatrick@google.com@RHEL_Server_875
- Install the necessary software components:
- sudo yum install -y docker kubectl kubernetes-cni
- Start the Docker service:
- sudo systemctl start docker
- Verify the Docker service status:
- sudo systemctl start docker
- Enable the Docker service to start on system boot:
- sudo systemctl enable docker
- 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.
- 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
- mkdir -p $HOME/.kube
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>
- # Use the command obtained in step 6 on each worker node
- Verify the cluster status:
- kubectl get nodes
- This command should display the master node and any joined worker nodes.
- 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.
- apiVersion: apps/v1
- Apply the deployment to the Kubernetes cluster:
- kubectl apply -f deployment.yaml
- Monitor the deployment status:
- kubectl get deployments
kubectl get pods - These commands will display the status of the deployment and the created pods.
- kubectl get deployments
- 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.
- Monitor the rolling update progress:
- kubectl rollout status deployment/my-deployment
- This command displays the status of the rolling update process.
- 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.