Useful cli commands Flashcards
Scaling deployments
k scale deploy
k scale deploy mynginx –replicas=3
k get A –selector app=mynginx
Set env variables
k set env deploy maria-deploy MARIADB_ROOT_PASSWORD=1234
Create CM from file or from literal
k create cm maria-pwd –from-file=maria-passwords
k create cm maria-pwd –from-literal=MARIADB_ROOT_PASSWORD=12345
Set deployment variable from cm
k set env deploy maria-deploy –from=configmap/maria-pwd
Expose port
k expose deploy mydep –port=8080 –type=NodePort
Label node
Set in Pod spec this label to run on specific node
k label nodes worker2 disktype=ssd
____
kind: Pod
apiVersion: v1
spec:
containers:
- name: nginx-cont
image: nginx
nodeSelector:
disktype: ssd
Read current context
Set config
k config view
k config –kubeconfig=~./kube/config –set-cluster mycluster –server=http://192.168.29.120 –certificate-authority=clusterca.crt
RBAC
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
services
servicename.namespace.svc.clustername
also look into /etc/resolv.conf for a pod to check FQDN
Taints only allow run pods with label disk=ssd
NoSchedule
PreferNoSchedule
NoExecute: migrate pods from this node
k taint nodes worker1 disk=ssd:NoSchedule
k taint nodes worker1 disk=ssd:NoSchedule-
Toleration allow to pods on nodes with taints
tolerations:
- key: “key1”
operator: “Equal”
value: “value1”
effect: “NoSchedule”
Scaling deployments
k scale delopy mydep –replicas=3
Provide env vars to pod (this does not work for deployments)
k run mynginx –image=nginx – env=”MYSQL_ROOT_PASSWORD=123”
Provide env vars to deploy
k create deploy mynginx –image=nginx
k set env deploy myngin MYSQL_ROOT_PASSWORD=123
Create env vars from config maps
k create cm –from-env-file=dbvars
k set env –from=configmap/mycm deploy/mydep