visit
alias k="kubectl"
export do="--dry-run=client -o yaml"
export do="--force --grace-period 0"
~/.vimrc
and include:set tabstop=2
set expandtab
set shiftwidth=2
k config set-credentials <name> \
--client-certificate=<path to .crt> \
--client-key=<path to .key>
k config set-context <context name> \
--cluster=<cluster name> \
--user=<name>
k config use-context <context name>
-o jsonpath="<filter>"
Know where the configuration files for kubelet
are stored:
/var/lib/kubelet/
Know where the configuration files for kubeadm are stored:
/etc/kubernetes/admin.conf
Know where the CNI configuration files are stored:
/etc/cni/inet.d/
Know where static pod configurations are stored:
/etc/kubernetes/manifests/
Most of the time, we will be using the dry run
option to create our template. This is why we created the do
environment variable at the beginning.
k -n <namespace> run <pod name> --image <image name> $do > pod-example.yaml
k -n <namespace> create deployment <dply name> --image <image name> --replicas <num> $do > dply.yaml
apiVersion:
metadata:
kind:
spec:
k top nodes
k top pods --containers=true
The most common steps will be:
Test the changes with the auth can-i
command.
k auth can-i <verb> <resources> --as=<user/sa> --namespace=<namespace>
We can create a DaemonSet object using as a template a Deployment YAML file. We just need to change the kind
entry, and remove the replicas
, strategy
and status
entries.
k -n <ns> create deployment <dply name> --image <img name> $do > daemonset.yaml
Get familiar with crictl
to start, stop, inspect, and delete containers.
kube-scheduler is a static Pod defined in the manifests we can find under /etc/kubernetes/manifests
by default. We can stop this pod by simply moving the manifest file from this directory to another one.
The way to schedule a Pod in a node is by using the following directive inside the spec
part:
nodeName
Have in mind that nodeSelector
as well as affinity and anti-affinity directives are actually used by the scheduler to decide in which node (if there is one) our Pod will be scheduled.
nodeSelector
, it uses node labels..spec.nodeSelector -> situation in a YAML file
spec:
nodeSelector:
<label>: <value>
nodeSelector
..spec.affinity.nodeAffinity.requiredDuringSchedulingIgnoredDuringExecution.nodeSelectorTerms.matchExpressions.[]
.spec.affinity.nodeAffinity.preferredDuringSchedulingIgnoredDuringExecution.nodeSelectorTerms.matchExpressions.[]
spec:
affinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key:
operator:
values:
-
spec:
affinity:
preferredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key:
operator:
values:
-
k taint nodes <node name> <key>=<value>:<effect>
k taint nodes <node name> <key>=<value>:<effect>-
.spec.tolerations.[] -> situation in a YAML file
spec:
tolerations:
- key:
operator:
value:
effect:
If you want to create a static Pod, you need to place the YAML manifest for that Pod inside the default manifest path. This path is configured in the Kubelet configuration file (/var/lib/kubelet/config.yaml
)
systemctl restart kubelet
k -n kube-system exec <pod-name> -- /bin/sh -c \
"ETCDCTL_API=3 etcdctl \
--endpoints=//127.0.0.1:2379 \
--cacert=/etc/kubernetes/pki/etcd/ca.crt \
--cert=/etc/kubernetes/pki/etcd/server.crt \
--key=/etc/kubernetes/pki/etcd/server.key \
snapshot save /var/lib/etcd/snapshot.db"