Deploying and Managing Applications with Kubernetes
Deploying Applications
Kubernetes provides several ways to deploy applications, including:
- Deployments: Declarative way to manage the lifecycle of stateless applications.
- StatefulSets: Manage the deployment and scaling of stateful applications, such as databases.
- DaemonSets: Ensure that a specific Pod runs on all (or some) Nodes in the cluster.
- Jobs and CronJobs: Run one-time or scheduled tasks.
Here's an example of a Deployment manifest:
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
Managing Applications
Kubernetes provides several tools and commands to manage the lifecycle of your applications:
kubectl apply
: Create or update a resource
kubectl get
: List resources
kubectl describe
: Show detailed information about a resource
kubectl delete
: Delete a resource
kubectl logs
: View the logs of a container
kubectl exec
: Execute a command in a container
For example, to scale the Nginx Deployment to 5 replicas:
kubectl scale deployment nginx-deployment --replicas=5
Updating Applications
Kubernetes supports rolling updates, which allow you to update your application with minimal downtime. You can update the container image or any other configuration in the Deployment manifest and apply the changes:
kubectl apply -f nginx-deployment.yaml
Kubernetes will then gradually roll out the new version, ensuring that the application remains available during the update process.
Rollbacks
If an update introduces issues, you can easily roll back to the previous version of your application using the kubectl rollout
command:
kubectl rollout undo deployment nginx-deployment
This will revert the Deployment to the previous stable version.