Useful cli commands Flashcards

1
Q

Scaling deployments

A

k scale deploy
k scale deploy mynginx –replicas=3
k get A –selector app=mynginx

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Set env variables

A

k set env deploy maria-deploy MARIADB_ROOT_PASSWORD=1234

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Create CM from file or from literal

A

k create cm maria-pwd –from-file=maria-passwords
k create cm maria-pwd –from-literal=MARIADB_ROOT_PASSWORD=12345

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Set deployment variable from cm

A

k set env deploy maria-deploy –from=configmap/maria-pwd

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Expose port

A

k expose deploy mydep –port=8080 –type=NodePort

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Label node
Set in Pod spec this label to run on specific node

A

k label nodes worker2 disktype=ssd
____
kind: Pod
apiVersion: v1
spec:
containers:
- name: nginx-cont
image: nginx
nodeSelector:
disktype: ssd

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Read current context
Set config

A

k config view
k config –kubeconfig=~./kube/config –set-cluster mycluster –server=http://192.168.29.120 –certificate-authority=clusterca.crt

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

RBAC

A

k create ns staff
k config get-context
useradd anna -s /bin/bash -G sudo -m
passwd anna
sudo su - anna
create private key:
openssl genrsa -out anna.key 2048
create cert signing request:
openssl req -new -key=anna.key -out=anna.csr -subj “/CN=anna/O=k8s”
sudo openssl x509 -req -in=anna.csr -CA=/etc/kubernetes/pki/ca.crt -CAkey=/etc/kubernetes/pki/ca.key -CAcreateserial -out=anna.crt -days=1800
mkdir .kube
sudo cp /etc/kubernetes/admin.conf .kube/config
sudo chown -R anna:anna .kube
k config set-credentials anna –client-certificate=/home/anna/anna.crt –client-key=/home/anna/anna.key

k config set-context anna-context –cluster=kubernetes –user=anna –namespace=staff
k config use-context anna-context
exit to be root user
k run mynginx –image=nginx -n staff
k create role annarole –verb=get,list –resource=pods -n staff
k create rolebinding annabnd –role=annarole –user=anna -n staff
sudo su - anna
k get pods=> mynginx

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

services

A

servicename.namespace.svc.clustername
also look into /etc/resolv.conf for a pod to check FQDN

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Taints only allow run pods with label disk=ssd

A

NoSchedule
PreferNoSchedule
NoExecute: migrate pods from this node
k taint nodes worker1 disk=ssd:NoSchedule
k taint nodes worker1 disk=ssd:NoSchedule-

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Toleration allow to pods on nodes with taints

A

tolerations:
- key: “key1”
operator: “Equal”
value: “value1”
effect: “NoSchedule”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Scaling deployments

A

k scale delopy mydep –replicas=3

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Provide env vars to pod (this does not work for deployments)

A

k run mynginx –image=nginx – env=”MYSQL_ROOT_PASSWORD=123”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Provide env vars to deploy

A

k create deploy mynginx –image=nginx
k set env deploy myngin MYSQL_ROOT_PASSWORD=123

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Create env vars from config maps

A

k create cm –from-env-file=dbvars
k set env –from=configmap/mycm deploy/mydep

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Generate new token and print this

A

kubeadm token create –print-join-command

17
Q

Metrics server

A

https://github.com/kubernetes-sigs/metrics-server

18
Q

Restore from backup

A

stop core services:
mv /etc/kubernetes/manifests/.yaml /etc/kubernetes
sudo crictl ps
sudo ETCDCTL_API=3 etcdctl snapshot restore /tmp/etcdbackup.db –data-dir /var/lib/etcd-backup
will restore in non-default folder
sudo ls -la /var/lib/etcd-backup/member
sudo vi /etc/kubernetes/etcd.yaml
go to volumes section, etcd-data
update path with /var/lib/etcd-backup
sudo mv /etc/kubernetes/
.yaml /etc/kubernetes/manifests
and check core services started working
sudo crictl ps

19
Q

apply network pod plugin

A

k apply -f https://docs.projectcalico.org/manifests/calico.yaml

20
Q

Install cluster

A

on CP node:
1. kubeadm init (there are options, check kubeadm init -h)
2. follow the output and create dir .kube, copy /etc/kubernetes/admin.conf to .kube/config. At this point kubectl get all should be working
3. install network pod plugin calico
On worker nodes:
kubeadm join

kubeadm reset - try to reset if something goes wrong
if the token is expire:
kubeadm token create –print-join-command

21
Q

backup etcd

A
  1. apt install etcd-client
  2. sudo ETCDCTL_API=3 etcdctl
  3. sudo ps aux | grep etcd
  4. sudo ETCDCTL_API=3 etcdctl –endpoints=localhost: 2379 –cacert=/etc/kubernetes/pki/etcd/ca.crt –cert=/etc/kubernetes/pki/etcd/server.crt –key=/etc/kubernetes/pki/etcd/server.key get / –prefix –keys-only
  5. sudo ETCDCTL_API=3 etcdctl –endpoints=localhost: 2379 –cacert=/etc/kubernetes/pki/etcd/ca.crt –cert=/etc/kubernetes/pki/etcd/server.crt –key=/etc/kubernetes/pki/etcd/server.key snapshot save /tmp/etcdbackup.db
  6. sudo ETCDCTL_API=3 etcdctl –write-out=table snapshot status /tmp/etcbackup.db