rm ~/.vimrc
k run nginx --image nginx --dry-run -oyaml > 1.yaml
vim 1.yaml
cat > ~/.vimrc <<EOF
set ts=2 sts=2 sw=2 et nu ai cuc cul
EOF
vim 1.yaml
alias hg='history|grep'
# FILE NAVIGATION AND ORGANISATION
mkdir `seq 20`
ls
cd 1/
cd ../2
cd ../3
# ALWAYS CREATE DRY-RUN YAML FILES WITH 1.yaml, 2.yaml or 3.yaml
k run nginx --image nginx --dry-run -oyaml > 1.yaml
vim 1.yaml
k create -f 1.yaml
k get pod --watch
k get pod nginx -oyaml > 2.yaml
vim 2.yaml
k apply -f 2.yaml
# 6 CLUSTERS IN EXAM
https://docs.linuxfoundation.org/tc-docs/certification/tips-cka-and-ckad
k config use-context [k8s|hk8s|bk8s|wk8s|ek8s|ik8s]
# NAMESPACE TRICK
N=namespace-asked-in-question
k delete ns $N
k create ns $N
k -n $N run question1 --image nginx
k -n $N edit pod question1
# FILENAME TRICK
mkdir -p complete/file/path/
touch complete/file/path/filename-asked-in-question
F=complete/file/path/filename-asked-in-question
echo $F
cp $F .
ls
vim $F
# HOW TO USE HELP IN COMMAND LINE
# Identify which objects can be created via command line
# and which objects need yaml to start with
k -h # IT'S ALL STARTS HERE
k expose -h # Use to expose pod or deployment to create a service
k create -h # Ingress, Deployments, SA, role, rolebinding, clusterrole, clusterrolebinding, serviceaccount
k create ingress -h # THIS ONE IS REALLY HANDY
k set -h
k set resources -h # THIS ONE IS REALLY HANDY TOO
k logs -h
k drain -h
k uncordon -h
k scale -h
k top -h
k top pod -h
k top pod --sort-by -h
# Network Policies need yaml first
https://kubernetes.io/docs/concepts/services-networking/network-policies/
# StorageClass, PersistentVolume, PersistentVolumeClaim need yaml first
https://kubernetes.io/docs/concepts/storage/storage-classes/
https://kubernetes.io/docs/tasks/configure-pod-container/configure-persistent-volume-storage/
# USE EXPLAIN COMMAND
# 1ST FOCUS ON .SPEC FIELD
# IF NOT THEN FOCUS ON .METADATA FIELD
k explain quota.spec --recursive
k explain limitrange.spec --recursive
k explain node --recursive
k explain pod.spec --recursive| grep -i nodesel
k explain deploy.spec --recursive | grep -i nodesel
k explain pod.spec --recursive| grep -i empty -C3
# DON'T ABANDON A COMMAND IF YOU DON'T INTEND TO USE IT IMMEDIATELY
# INSTEAD PRESS CTRL+A TO GO TO START AND ADD A `#` IN FRONT
ETCDCTL_API=3 etcdctl snapshot save \
/tmp/etcd-backup.db \
--cacert /etc/kubernetes/pki/etcd/ca.crt \
--cert /etc/kubernetes/pki/apiserver-etcd-client.crt \
--key /etc/kubernetes/pki/apiserver-etcd-client.key
# GET COMFORTABLE WITH SYSTEMCTL
# sudo -i # DO SUDO -I if you can
systemctl status kubelet # CHECK SERVICE STATUS
systemctl enable kubelet # ENABLE THE SERVICE
systemctl start kubelet # START THE SERVICE
systemctl stop kubelet # STOP THE SERVICE
systemctl daemon-reload # DAEMON RELOAD
systemctl restart kubelet # RESTART IF YOU MADE ANY CONFIG CHANGES
# VIM TIPS
SHIFT C
vim 1.yaml
SHIFT V -> ARROWS ↑↓ -> y (copy) -> Goto line after which you want to copy -> p (paste after)
vim 1.yaml
SHIFT V -> ARROWS ↑↓ -> `><` -> . (repeat)
vim 1.yaml
k get node
ssh minikube
# sudo -i # become root
# exit # sudo
# exit # exit node
# now you are back to client terminal
hg question1