Kubectl Deploymant Workflow
The process for deploying applications using Kubectl involves several key steps:
- Verify cluster readiness (Minikube or kubeadm)
- Create Deployment configuration
- Apply the configuration
- Verify deployment status
Deploying a Sample Web Application
1. Creating the Deployment Configuration
A Deployment object manages application instances through ReplicaSets. Here's a sample configuration:
apiVersion: apps/v1
kind: Deployment
metadata:
name: webapp-deployment
spec:
replicas: 3
selector:
matchLabels:
service: webapp
template:
metadata:
labels:
service: webapp
spec:
containers:
- name: web-container
image: nginx:latest
ports:
- containerPort: 80
Key components:
replicas: Number of identical Pod instancesselector: Criteria for identifying managed Podstemplate: Blueprint for Pod creation
2. Applying the Deployment
Execute the deployment using:
kubectl apply -f webapp-deployment.yaml
3. Verifying Deployment Status
Check deployement progress with:
kubectl get deployment webapp-deployment
Output columns indicate:
- READY: Current vs. desired Pod count
- UP-TO-DATE: Updated replicas
- AVAILABLE: Ready-to-use replicas
- AGE: Time since creation
To inspect related ReplicaSets:
kubectl get replicasets -lservice=webapp
ReplicaSet names follow the pattern [deployment-name]-[random-hash]. View Pod details with:
kubectl get pods -lservice=webapp --show-labels