Contents

Kubernetes Tips

Kubernetes Usage Config

Alias in ~/.bashrc

1
2
3
alias k="kubectl"
alias kc="kubectl config get-contexts"
alias kn="kubectl config set-context --current --namespace"

Output YAML in ~/.bashrc

1
export do="--dry-run=client -o=yaml"

Vim Config in ~/.vimrc

1
2
3
set tabstop=2
set expandtab
set shiftwidth=2

After editing *.service

1
systemctl daemon-reload

StatefulSet

1
k get sts

Kubernetes Resource Usage

1
2
k top node
k top pod --container=true

Manually Scheduling without Scheduler

nodeName
The nodeName field is for that.

Replace Command

1
k replace -f nginx.yaml --force

Affinity

POD Affinity

POD Affinity
Inter-pod affinity and anti-affinity allow you to constrain which nodes your pod is eligible to be scheduled based on labels on pods that are already running on the node rather than based on labels on nodes.

Node Affinity

Node Affinity
Node affinity is conceptually similar to nodeSelector – it allows you to constrain which nodes your pod is eligible to be scheduled on, based on labels on the node.

CIDR

POD CIDR

1
k describe node <node-name>

Service CIDR

1
cat /etc/kubernetes/manifests/kube-apiserver.yaml

Events

1
k get ev

API Resources

1
k api-resources

Find First to be Terminated

1
k describe pod | less -p Requests

JSONPath

1
k get pods -o=jsonpath="{range .items[*]}{.metadata.name} {.status.qosClass}{'\n'}"

Create a YAML with Command

1
k run tmp-api-contact --image=curlimages/curl:7.65.3 $do --command > curl.yaml -- sh -c 'sleep 1d'

Quick Delete a POD

1
k delete pod nginx --grace-period 0 --force

SSH with Command

1
2
ssh cluster1-worker1 "docker ps | grep tigers-reunite"
ssh cluster1-worker1 "docker logs a934ce61f4d4" &> /opt/course/17/pod-container.log