This repository provides a simple guide and example commands to help you understand and work with Kubernetes Deployments, DaemonSets, and StatefulSets.
Deployments are used by 99.99% of people to deploy their applications. They include ReplicaSets and Pods.
DaemonSets ensure that a pod is run on each node in the cluster. This is typically used for log collection and monitoring.
StatefulSets maintain the identity of pods, ensuring the hostname remains the same, which is crucial for stateful applications like MongoDB and MySQL.
kubectl create deployment testapp --image kiran2361993/kubegame:v1 --replicas 3 --dry-run -o yaml
Add the following container to the deployment:
- Image:
kiran2361993/mydb:v1
- Name:
Database
Labels are key-value pairs used to pass information.
kubectl run testpod1 --image nginx:latest
kubectl apply -f deployment.yaml
kubectl get pods
Annotations can pass information such as:
- Info: "This Deployment file has been created by Saikiran Pinapathruni"
- Email: "[email protected]"
- Owner: "Saikiran Pinapathruni"
Set environment variables at the container level:
env:
- name: DB_NAME
value: "mysqldb"
- name: DB_PORT
value: "3306"
- name: DB_URL
value: "saikiranpi.in/mydb"
kubectl describe pod <podname>
kubectl exec -it <podname> -- bash
env
kubectl expose deployment testapp --name sv1 --port 8000 --target-port 80 --type NodePort
kubectl expose deployment testapp --name sv2 --port 5000 --target-port 5000 --type NodePort
kubectl explain deployment.spec.strategy
Under spec:
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 0%
kubectl edit deployment testapp
Under spec:
minReadySeconds: 10
maxUnavailable: 0
DaemonSets ensure that one pod is run on each node.
StatefulSets maintain the identity of pods, ensuring the hostname remains the same.
What is the difference between Deployments, DaemonSets, and StatefulSets?
- Deployments: Used for stateless applications, allowing for scaling up and down without dependencies on pod names.
- DaemonSets: Ensure one pod per node, typically used for log collection and monitoring.
- StatefulSets: Maintain pod identity, crucial for stateful applications like databases.