Daily Archives: 27.03.2018
Kubectl helpful commands
k8s cheatsheet. Get all pods by label
1 |
$ kubectl --kubeconfig <config file> get po -lapp=<pod name without hash> -Lversion,cfg,infra-cfg |
Exec into the pod
1 |
$ kubectl --kubeconfig <config file> exec -it <pod name> sh |
Port forwarding
1 |
$ kubectl --kubeconfig <config file> port-forward <pod name> <local port>:<remote port> |
Getting logs
1 |
$ kubectl --kubeconfig <config file> logs <pod name> <pod name without hash> |
Get replica limits from configs:
1 2 3 4 5 |
$ kubectl --kubeconfig <config file> get hpa <pod name without hash> # more details $ kubectl --kubeconfig <config file> get deployment <pod name without hash> --output=yaml $ kubectl --kubeconfig <config file> describe deployments <pod name without hash> $ kubectl --kubeconfig <config file> describe pod <pod name without hash> # CPU and memory limits/requests (quota) |
Remove pod from load balancing to debug startup errors:
1 2 3 |
$ kubectl --kubeconfig <config file> label pod <pod_name> <labels to remove> # and remove (kill the pod) afterwards $ kubectl --kubeconfig <config file> delete pod <pod_name> |
Scale (up/down) pods:
1 2 3 4 |
$ kubectl --context=xx-live-default get pods -l app=boblin -o wide $ kubectl --context=xx-live-default scale --current-replicas=12 --replicas=3 deployment/boblin $ kubectl --context=xx-live-default delete pods boblin-3353777365-qjdpd $ kubectl --kubeconfig <config file> scale deployment <pod name without hash> --current-replicas=0 --replicas=2 |
1 2 3 4 |
$ kubectl --kubeconfig <config file> get po -lapp=<label> -Lversion,cfg $ watch -n 1 kubectl --kubeconfig <config file> get po -lapp=<label> -Lversion,cfg $ kubectl --kubeconfig <config file> exec <exact pod hash> sh $ kubectl --kubeconfig <config file> get hpa <label> |
More commands here: https://kubernetes.io/docs/reference/kubectl/overview/ https://kubernetes.io/docs/reference/kubectl/cheatsheet/