Kubernetes Mock Exam 3

 Task 1

1. Create service account

#kubectl create serviceaccount pvviewer

2. Create cluster role - list pv

#kubectl create clusterrole pvviewer-role --resource=persistentvolumes --verb=list

3. Create cluster rolebinding 

#kubectl create clusterrolebinding pvviewer-role-binding --clusterrole=pvviewer-role --serviceaccount=default:pvviewer

4. Create pod with service account

#kubectl run --generator=run-pod/v1 pvviewer --image=redis --dry-run -o yaml > pod.yaml

Add yaml file

serviceAccountName: pvviewer

#kubectl create -f pod.yaml

Document: configure service account


Task 2

Document: cheatsheet - get ExternalIP of all nodes

#kubectl get nodes -o jsonpath='{.items[*].status.addresses[?(@.type="InternalIP")].address}'  > /root/node_ips

Task 3

Create pod with two containers with different images

#kubectl run --generator=run-pod/v1 multi-pod --image=nginx --dry-run -o yaml > multi-pod.yaml


Change the yaml file

Add second pod and env


spec:

  containers:

  - image: nginx

    name: alpha

    env:

    - name: name

      value: alpha

  - image: busybox

    name: beta

    command: ["sleep","4800"]

    env: 

    - name: name

      value: beta


#kubectl create -f multi-pod.yaml


Task 4

Create pod with specific cpu and memory limit

#kubectl run --generator=run-pod/v1 lion --image=redis:alpine --dry-run -o yaml > lion.yaml


Kubernetes.io --> Pod with resource limits

Add following to yaml file

resources:

   limits:

      cpu: "2"

      memory: "500Mi"


Task 5

Trouble shooting Pod / service

#kubectl get pod

#kubectl get services


Create test pod to check

#kubectl run --generator=run-pod/v1 test-np --image=busybox:1.28 --rm -it -- sh 

#nc -z -v -w 2 <service name> 80


#kubectl get networkpolicy

#kubectl describe netpol default-deny


Kubernetes.io --> network policies


apiVersion: networking.k8s.io/v1

kind: NetworPolicy

metadate: 

     name: <in the question>

     namespace: default

spec: 

    podSelector: 

        matchLabels: 

             <label in pod>

    policyTypes: 

    - Ingress

    ingress: 

    - ports:

      - port: 80

        protocol: TCP


Task 6: create pod to specific node

#kubectl get node

#kubectl taint node node01 env_type=production:NoSchedule

#kubectl describe node node01|grep -i taint


#kubectl run --generator=run-pod/v1 dev-redis --image=redis:alphine 

#kubectl get pod -o wide


#kubectl get pod dev-redis -o yaml > prod-redis.yaml

vi prod-redis.yaml


Change the name to prod-redis


keep tolerations part

tolerations:

- effect: NoSchedule

  key: env_type

  operator: Equal

  value: production


Task 7: create pod with label in specific namespace

#kubectl get ns

#kubectl create ns hr

#kubectl run --generator=run-pod/v1 hr-pod --image=redis:alpine --labels=environment=production,tier=frontend --namespace=hr

#kubectl -h hr get pods --show-labels


Task 8: configuration file troubleshooting

#kubectl cluster-info --kubeconfig=/root/super.kubeconfig


find the server port is wrong

fix by update the port from 2379 --> 6443


Task 9: deployment trouble shooting

#kubectl get deployments

#kubectl describe deployment


#kubectl scale deployment nginx-deploy --replicas=3

#kubectl get deployments

#kubectl describe deployment nginx-deploy

#kubectl get pod

#kubectl describe pod <pod name>

#kubectl -n kube-system get pods --> find controller manger is broken


cd /etc/kubernetes/manifests


name spell is wrong. need to fix it. 



Comments

Popular posts from this blog

Nginx Proxy & Load Balance & LNMP

Snort+barnyard2+Snorby CentOS 6.5_64 Installation

ORACLE Error