Kubernetes orchestrates containers at scale, managing deployment, scaling, and operations of containerized applications.
Core Concepts
Pods
Smallest deployable unit. Contains one or more containers.
Services
Network abstraction providing stable IP and DNS name.
Deployments
Manages replica sets and rolling updates.
Namespaces
Virtual clusters for organizing resources.
Basic Commands
kubectl get pods # List pods
kubectl get services # List services
kubectl get deployments # List deployments
kubectl describe pod name # Pod details
kubectl logs pod-name # Pod logs
kubectl exec -it pod-name -- /bin/sh # Execute in pod
Deployment Example
apiVersion: apps/v1
kind: Deployment
metadata:
name: myapp
spec:
replicas: 3
selector:
matchLabels:
app: myapp
template:
metadata:
labels:
app: myapp
spec:
containers:
- name: myapp
image: myapp:latest
ports:
- containerPort: 80
Service Example
apiVersion: v1
kind: Service
metadata:
name: myapp-service
spec:
selector:
app: myapp
ports:
- port: 80
targetPort: 80
type: LoadBalancer
Apply Configuration
kubectl apply -f deployment.yaml
kubectl apply -f service.yaml
kubectl get all
Scaling
kubectl scale deployment myapp --replicas=5
kubectl autoscale deployment myapp --min=2 --max=10
Updates
kubectl set image deployment/myapp myapp=myapp:v2
kubectl rollout status deployment/myapp
kubectl rollout undo deployment/myapp
ConfigMaps and Secrets
kubectl create configmap myconfig --from-file=config.properties
kubectl create secret generic mysecret --from-literal=key=value
Best Practices
- Use declarative configuration
- Version control all manifests
- Use namespaces for organization
- Set resource limits
- Implement health checks
- Use secrets for sensitive data
Kubernetes is the foundation of modern container orchestration.