DEV Community

Alen
Alen

Posted on • Originally published at orbjet.org

K8s Med Kit

Kubernetes is pushing 1.16 and perhaps the latest version in 2019. Even though it doesn't sound much in version numbers, it holds a long way of improvements since it's first appearance in 2014.

As k8s is created to ease the orchestration of containers and aid with networking, persistent data and security, it's often good to have some mission-critical commands attached to your toolbelt which, in the time of need and depending of the case, you'll most likely use.

In order to apply these, a fair knowledge of kubernetes is presumed.
Here is a list of specific use cases (most of these are ad-hoc commands):

1- Tweak resources on a specific deployment:

$ kubectl set resources deployment <name-of-deployment> --limits=cpu=1,memory=1Gi --requests=cpu=500m,memory=500Mi -n <name-of-namespace>

2- Even with autoscaling, you might want to change the number of instances manually (sometimes):

$ kubectl scale deployments/<name-of-deployment> --replicas=<number> -n <name-of-namespace> 

3- Change the image version running - aka rollback to a different image version:

$ kubectl set image deployment/<name-of-deployment> <app-name>=<registry.url:PORT>/<app-name>:<build-version> -n <name-of-namespace>

4- If one of the nodes is acting differently than usual, it's good to get some insight

$ kubectl describe nodes <name-of-node>

5- Get insight of what happened in the cluster:

$ kubectl get events --all-namespaces

6- Get information of the namespace:

$ kubectl get all -n namespace

7- Delete all deployments that have not Running status. Caution! This should be done if you have evicting or non attached deployments and should be used as least resort. A pro-argument would be that you can't deploy new deployments due to a queue buildup and instead of manually removing pods, you resort to a more automated removal.

$ kubectl get pods --all-namespaces --field-selector 'status.phase!=Running' -o json | kubectl delete -f -

8- Delete a pod by - force (similiar to point 7, but defining a pod):

$ kubectl delete pods <name-of-pod> --grace-period=0 --force

Bonus point:

In this post I reference Kubernetes with k8s. If you search the internet or read technical texts, you'll often find a thin line between the names used interchangeably. Sometimes it's Kubernetes sometimes k8s. The former is the official name, the latter is the slang abbreviation to ease referencing to it. The mystery behind k8s is actually really simple - k (number of letters between the first an last letter, hence 8) s.
You could play with this method and apply it to different long-named words/brands.

Guess what would be i4e :)

Reposted from orbjet.org

Top comments (0)