Kubernetes

Some useful Kubernets commands to manage a deployment

Apply Config

kubectl apply -f <file.yaml> --namespace <namespace>

Scale Down deployment

kubectl scale --replicas 0 --namespace <namespace> -f <file.yaml>

Destroy Deployment

kubectl delete -f <file.yaml>

Get pods status

kubectl get pods --namespace <namespace> -w

Resource Details

kubectl describe <resource> <resource_name> --namespace <namespace>

kubectl describe pods dev-mariadb-0 --namespace my-namespace

Follow pod logs

kubectl logs <pod_name> --namespace <namespace> -f

List pods containers

kubectl get pods <pod_name> -o jsonpath='{.spec.containers[*].name}' --namespace <namespace>

Attacch to a Pod container shell

kubectl exec --stdin --tty <pod_name> --namespace <namespace> -c <container_name> -- /bin/sh

Delete namepsace

kubectl delete ns <namespace-name>