Kubernetes🔗
Installation🔗
Install kubectl
and minikube
for local testing
# kubectl
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
# minikube
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
sudo install minikube-linux-amd64 /usr/local/bin/minikube
minikube start --driver=docker
Essential Commands🔗
Category | Command | Description |
---|---|---|
Pods | kubectl get pods -A |
List all pods |
kubectl describe pod <name> |
Inspect pod details | |
Deployments | kubectl rollout status deploy/<name> |
Check deployment |
kubectl scale deploy/<name> --replicas=3 |
Scale replicas | |
Services | kubectl expose deploy/<name> --port=80 |
Create service |
Debugging | kubectl logs <pod> -f |
Stream logs |
kubectl exec -it <pod> -- sh |
Enter container shell | |
Sample Deployment (deploy.yml
)
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:alpine
ports:
- containerPort: 80
Apply
Tips🔗
- Context Switching
- port forwarding
- resources limits
Security Best Practices🔗
- Use
Role-Based Access Control(RBAC)
- Enable
Netowrk Policies
- Scan images with
Trivy