k8s 공식 문서 - kubectl Cheat Sheet
source <(kubectl completion bash) # setup autocomplete in bash into the current shell, bash-completion package should be installed first.
echo "source <(kubectl completion bash)" >> ~/.bashrc # add autocomplete permanently to your bash shell.
kubectl [command] [type] [name] [flags]
command
: create, get, delete, edittype
: node, pod, servicename
: 리소스의 이름flags
: --help, -o options, --dry-run$ kubectl config use-context hk8s
Switched to context "hk8s".
$ kubectl config current-context
hk8s
/var/CKA2022/hk8s-node-info.txt
파일로 저장하시오.$ kubectl get nodes
NAME STATUS ROLES AGE VERSION
hk8s-m Ready control-plane,master 161d v1.22.4
hk8s-w1 Ready <none> 161d v1.22.4
hk8s-w2 NotReady <none> 152d v1.22.4
$ kubectl get nodes | cut -d' ' -f1
NAME
hk8s-m
hk8s-w1
hk8s-w2
$ kubectl get nodes | cut -d' ' -f1 | grep -v NAME
hk8s-m
hk8s-w1
hk8s-w2
$ kubectl get nodes | cut -d' ' -f1 | grep -v NAME > /var/CKA2022/hk8s-node-info.txt
$ cat /var/CKA2022/hk8s-node-info.txt
hk8s-m
hk8s-w1
hk8s-w2
/var/CKA2022/hk8s-node-ready.txt
파일에 저장하시오.$ kubectl get nodes
NAME STATUS ROLES AGE VERSION
hk8s-m Ready control-plane,master 161d v1.22.4
hk8s-w1 Ready <none> 161d v1.22.4
hk8s-w2 NotReady <none> 152d v1.22.4
$ kubectl get nodes | grep -i -w ready
hk8s-m Ready control-plane,master 161d v1.22.4
hk8s-w1 Ready <none> 161d v1.22.4
$ kubectl get nodes | grep -i -w ready | cut -d' ' -f1
hk8s-m
hk8s-w1
$ kubectl get nodes | grep -i -w ready | cut -d' ' -f1 > /var/CKA2022/hk8s-node-ready.txt
$ cat /var/CKA2022/hk8s-node-ready.txt
hk8s-m
hk8s-w1
$ kubectl config use-context k8s
Switched to context "k8s".
$ kubectl config current-context
k8s
$ kubectl cluster-info
Kubernetes control plane is running at https://k8s-master:6443
CoreDNS is running at https://k8s-master:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
/var/CKA2022/k8s_cni_name.txt
에 저장하시오$ ssh k8s-master
$ ls /etc/cni/net.d/
10-flannel.conflist
$ echo "flannel" > /var/CKA2022/k8s_cni_name.txt
$ cat /var/CKA2022/k8s_cni_name.txt
flannel
/var/CKA2022/k8s-node-ready.txt
에 저장하시오.$ kubectl get nodes | grep -i -w ready | cut -d' ' -f1 > /var/CKA2022/k8s-node-ready.txt
$ cat /var/CKA2022/k8s-node-ready.txt
k8s-master
k8s-worker1