Official K8s Cheat Sheet: https://kubernetes.io/docs/reference/kubectl/cheatsheet/
- Check to which cluster you are connected to:
kubectl config current-context
- Get current pods:
kubectl get pod -n [namespace]
- Get autoscale config (hpa):
kubectl get hpa -n [namespace]
- Describe a pod:
kubectl describe pod [pod name] -n [namespace]
- Connect to a pod:
kubectl exec -it [pod name] -- /bin/bash
- Get pod logs:
kubectl logs [pod name]
- Get SSL certificates for namespace (used in ingress to allow HTTPS):
kubectl describe managedcertificate -n [namespace]
- Get deployment image tag:
gcloud container images list-tags gcr.io/[project id]/[image name] --limit 1
- Get deployment yaml:
kubectl get deploy [deployment] -o yaml --export
- Port foward:
kubectl port-foward -n [namespace] [pod] [local port]:[remote / pod port]
- To run a command continuously:
while ($true) { [command] | Out-Host; Sleep 10; Clear }
- Apply changes inside a file:
kubectl apply -f [path to yaml file]
- Delete evicted pods:
kubectl -n [namespace] delete pods --field-selector=status.phase=Failed
- Delete a deployment:
kubectl delete -f [path to yaml file]
- Delete all pods:
kubectl delete --all pods -n [namespace]
- Reload configs:
kubectl rollout restart deployment/name
- Scale deployment:
kubectl -n [namespace] scale deploy [deployment name] --replicas=[num replicas]
(if num replicas is set to 0, stops the current deployment) - Patch pod yaml: `kubectl patch [cronjobs / deployment] [cronscale / deployment name] -p '{"spec" : {"attribute" : value }}' -n [namespace]
- Deploy:
./k8s/deploy.sh [deployment id] [environment] [path to yaml file]
- Rollback Deployment:
kubectl rollout undo deployment/[deployment name] -n [namespace]
- Get deployments:
kubectl get deploy -n [namespace]
- Restart Deployment:
kubectl rollout restart deployment [deployment name] -n [namespace]
- Reserve global static IP address:
gcloud compute addresses create [ip name] --global
- Create secret key from username and password:
kubectl create secret generic cloudsql-db-credentials -n [namespace] --from-literal=username=[username] --from-literal=password=[password]
- Create secret key from file:
kubectl create secret generic cloudsql-instance-credentials -n [namespace] --from-file= [local-key-file.json]=[screts-key-file.json]