Kubernetes cheatsheet#
Debugging using events#
Important
Always check the pods and deployment versions in the namespace to make sure you aren't debugging an issue in a version that's not the one you would expect
Events are a great way to understand what's going on under the hood in a Kubernetes cluster. By looking at them you can see if probes are failing, and other important signals from your cluster.
Get events for the whole namespace:
kubectl -n codacy get events --sort-by=.metadata.creationTimestamp
Get error events:
kubectl -n codacy get events --sort-by=.metadata.creationTimestamp --field-selector type=Error
Get warning events:
kubectl -n codacy get events --sort-by=.metadata.creationTimestamp --field-selector type=Warning
Get events from a specific pod:
kubectl -n codacy get events --sort-by=.metadata.creationTimestamp --field-selector involvedObject.name=<POD-NAME>
Helm#
Check all the previous releases in your namespace:
helm -n codacy history codacy
Rollback to a specific revision:
helm -n codacy rollback codacy <REVISION>
Edit configmap#
kubectl get configmaps
and
kubectl edit configmap <configmap-name>
Restart deployment of daemonset#
daemonsets#
kubectl get daemonsets
and
kubectl rollout restart daemonset/<daemonset-name>
deployment#
kubectl get deployment
and
kubectl rollout restart deployment/<deployment-name>
and
kubectl rollout status deployment/<deployment-name> -w
Read logs#
daemonset with multiple containers#
kubectl logs daemonset/<daemonset-name> <container-name> -f
service#
kubectl get svc
and
kubectl logs -l $(kubectl get svc/<service-name> -o=json | jq ".spec.selector" | jq -r 'to_entries|map("\(.key)=\(.value|tostring)")|.[]' | sed -e 'H;${x;s/\n/,/g;s/^,//;p;};d') -f
Open shell inside container#
kubectl exec -it daemonset/<daemonset-name> -c <container-name> sh
or
kubectl exec -it deployment/<deployment-name> sh
MicroK8s#
Session Manager SSH#
When using AWS Session Manager, to connect to the instance where you installed microk8s, since the CLI is very limited you will benefit from using these aliases:
alias kubectl='sudo microk8s.kubectl -n <namespace-name>'
alias helm='sudo helm'
Share your feedback 📢
Did this page help you?
Thanks for the feedback! Is there anything else you'd like to tell us about this page?
255 characters left
We're sorry to hear that. Please let us know what we can improve:
255 characters left
Alternatively, you can create a more detailed issue on our GitHub repository.
Thanks for helping improve the Codacy documentation.
Edit this page on GitHub if you notice something wrong or missing.
If you have a question or need help please contact [email protected].