Skip to content

Kubernetes cheatsheet

How to install a custom Codacy version


sudo git clone git:// -b <YOUR-BRANCH>
helm dep build ./chart/codacy
helm upgrade --install codacy ./chart/codacy/ --namespace codacy --atomic --timeout=300 --values ./<YOUR-VALUES-FILE>


(cd chart; sudo git fetch --all --prune --tags; sudo git reset --hard origin/<YOUR-BRANCH>;)
helm dep build ./chart/codacy
helm upgrade --install codacy ./chart/codacy/ --namespace codacy --atomic --timeout=300 --values ./<YOUR-VALUES-FILE>



Always check the pods and deployment versions in the namespace to make sure you are not debugging an issue in a version that is not the one you would expect


Events are a great way to understand what is 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<POD-NAME>


Check all the previous releases in your namespace:

helm -n codacy history codacy

Rollback to a specific revision:

helm -n codacy rollback codacy <REVISION>

Clean the namespace

helm -n codacy uninstall codacy
kubectl -n codacy delete --all pod &
kubectl -n codacy delete --all pvc &
kubectl -n codacy delete --all pv  &
kubectl -n codacy delete --all job &
sleep 5
kubectl -n codacy patch pvc -p '{"metadata":{"finalizers":null}}' $(kubectl -n codacy get pvc -o jsonpath='{.items[*]}')
kubectl -n codacy patch pv -p '{"metadata":{"finalizers":null}}' $(kubectl -n codacy get pv -o jsonpath='{.items[*]}')
sleep 5
kubectl -n codacy delete pod $(kubectl -n codacy get pod -o jsonpath='{.items[*]}') --force --grace-period=0
kubectl -n codacy get pod &
kubectl -n codacy get pvc &
kubectl -n codacy get pv  &
kubectl -n codacy get job &

Check uninstall was successful

ps aux | grep -i kubectl

Edit configmap

kubectl get configmaps


kubectl edit configmap <configmap-name>

Restart deployment of daemonset


kubectl get daemonsets


kubectl rollout restart daemonset/<daemonset-name>


kubectl get deployment


kubectl rollout restart deployment/<deployment-name>


kubectl rollout status deployment/<deployment-name> -w

Read logs

daemonset with multiple containers

kubectl logs daemonset/<daemonset-name> <container-name> -f


kubectl get svc


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


kubectl exec -it deployment/<deployment-name> sh


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'
Last update: September 29, 2020