Skip to content

Latest commit

 

History

History

README.md

kubernetes-playground

My K8S Kubernetes playground 🚀

Install Rancher Desktop on Fedora 35

$ yum update -y 

Download yum repo file of the Rancher Desktop:

$ curl https://download.opensuse.org/repositories/isv:/Rancher:/stable/rpm/isv:Rancher:stable.repo -o /etc/yum.repos.d/_rancher-desktop.repo 

Install Fedora virtualizations drivers:

$ dnf install @virtualization -y
$ dnf group install --with-optional virtualization
$ systemctl start libvirtd
$ systemctl enable libvirtd

Update yum cache

$ yum makecache

Install rancher-desktop

$ yum install rancher-desktop

Cheat Sheet

List contexts

kubectl kubecconfig get-contexts

Change context

kubectx <context-name>

Get nodes

kubectl get nodes

Get more information

kubectl get nodes -o json -o wide

Get value with JSONPath sytax

kubectl get nodes minikube -o jsonpath --template={.spec.podCIDR} 

Resource hot edit

kubectl edit <resource> <object-name>

Resources label

kubectl label pods bar color=red
kubectl label pods bar color=blue --overwrite
kubectl label pods bar color-

List containers in POD

kubectl get pods <pod-name> -o jsonpath='{.spec.containers[*].name}'

View container log in POD

kubectl logs <pod-name> -c <container-name> -f

Exec command in containers

kubectl exec -it <pod-name> -- bash

Follow main process in POD (like logs, but with stdin available)

kubectl attach -it <pod-name>

Copy files to and from pod

kubectl <pod-name>:/var/local/xtpo /home/user/

Expose POD ports

kubectl port-forward <pod-name> 8080:80 

Expose SERVICE ports

kubectl port-forward services/<service-name> 

Get ReplicaSet details

kubectl describe rs kuard

Check POD owner references

kubectl get pods <pod> -o yaml | grep -A 10 ownerReferences

Scale Replicas (imperative way)

kubectl scale replicaset <replicaset> --replicas=4 

Enable Autoscale (HPA), 2..5 replicas by 80% cpu usage

kubectl autoscale rs kuard --min=2 --max=5 --cpu-percent=80

Get deployment labels

kubectl get deployments kuard -o jsonpath --template {.spec.selector.matchLabels}

Filter Replica Set by label

kubectl get replicasets -l run=kuard

Backup deployment

kubectl get deployment <deployment-name> -o yaml > bkp-deploy.yaml
kubectl replace -f <deployment-file .yml> --save-config

Get rollout history

kubectl rollout history deployment kuard 

To add change cause, add value to spec.template.metadata.annotations.kubernetes.io/change-cause

Get rollout informations of the specific version

kubectl rollout history deployment kuard --revision=2

Undo rollout

kubectl rollout undo deployments kuard

Rollout to specific version

kubectl rollout undo deployment kuard --to-revision=3