Skip to main content

Kubernetes cluster Administration notes (WIP)

Kubectl

Show yaml

kubectl get deployments/bookstack -o yaml

Scale

kubectl scale deployment/name --replicas=2

 

Drain nodes

Drain node

kubectl drain host.name.local --ignore-daemonsets

Put node back to ready

kubectl uncordon host.name.local

Replace a new node

Delete a node

kubectl delete node [node_name]

Generate a new token:

kubeadm token generate

List the tokens:

kubeadm token list

Print the kubeadm join command to join a node to the cluster:

kubeadm token create [token_name] --ttl 2h --print-join-command

Create etcd snapshot

Get the etcd binaries:

wget https://github.com/etcd-io/etcd/releases/download/v3.3.12/etcd-v3.3.12-linux-amd64.tar.gz

Unzip the compressed binaries:

tar xvf etcd-v3.3.12-linux-amd64.tar.gz

Move the files into /usr/local/bin:

mv etcd-v3.3.12-linux-amd64/etcd* /usr/local/bin

Take a snapshot of the etcd datastore using etcdctl:

ETCDCTL_API=3 etcdctl snapshot save snapshot.db --cacert /etc/kubernetes/pki/etcd/server.crt --cert /etc/kubernetes/pki/etcd/ca.crt --key /etc/kubernetes/pki/etcd/ca.key

View the help page for etcdctl:

ETCDCTL_API=3 etcdctl --help

Browse to the folder that contains the certificate files:

cd /etc/kubernetes/pki/etcd/

View that the snapshot was successful:

ETCDCTL_API=3 etcdctl --write-out=table snapshot status snapshot.db

Backup etcd snapshot

Zip up the contents of the etcd directory:

tar -zcvf etcd.tar.gz /etc/kubernetes/pki/etcd