0% found this document useful (0 votes)
13 views5 pages

Kubernetes Commands for Interviews

Kubernetes interview questions
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views5 pages

Kubernetes Commands for Interviews

Kubernetes interview questions
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

KUBERNETES

1. What is kubernetes
2. Explain kubernetes architecture – master node & worker node
Master node – kube api server; etcd keyvalue store; kube scheduler; kube controller manager
Worker node – kubelet, kubelet proxy, container runtime
Nodes – Node status, Management, API Object
Communications – Inter container & Inter Pod communications
3. Explain container network interface
4. What is kubectl – cli tool
5. What is kubernetes dashboard
6. Kubernetes objects – Pods, Services, Labels, Selectors, Replication Controller, Deployment
Object, deployment controller, volumes
7. Types of services – ClusterIP, Nodeport, Load Balancer, External IP
8. Explain pod life cycle – pod phase, pod condition, container probes, pod lifetime
9. Explain configmaps and types
10. Explain Private registry authentication
11. Explain image pull secret approach
12. Explain container lifecycle hook
Follow these steps to implement container lifecycle hooks:
Add hook property to pod description yaml.
apiVersion: v1
kind: Pod
metadata:
name: lifecycle-hook-demo
spec:
containers:
- name: lifecycle-hook-container
image: nginx
lifecycle:
postStart:
exec:
command: ["/bin/sh", "-c", "echo Hello from Fresco Team> /usr/share/message"]
preStop:
exec:
command: ["/usr/sbin/nginx","-s","quit"]
Create the Pod.
kubectl create -f <above_config.yaml>
To verify the step, get inside the container.
kubectl exec -it lifecycle-hook-demo -- /bin/bash
Use cat the file to see a message
cat /usr/share/message
You should see Hello from Fresco Team message.
13. Explain pod’s life
This is how a Pod's life goes.
Pods are created.
Pods are assigned a Unique ID(UID).
Scheduled to a random Node.
They run and server requests.
Wait for graceful termination (according to restart policy).
If a node dies before that pods are scheduled for recreation, a new pod is created with new UID.
The old pod's state is not taken into consideration
14. Command to see running pods
Kubectl get pods
15. What is namespace in kubernetes
16. Creating a NameSpace
Create yaml file of kind: namespace.
apiVersion: v1
kind: Namespace
metadata:
name: testns
Create it by using 'kubectl`.
kubectl create -f <above_file.yaml>
Verify namespace creation by executing
kubectl get namespaces
17. Deploy namespace in pod using yaml
apiVersion: v1
kind: Pod
metadata:
name:lifecycle-hook-demo
namespace: testns
spec:
containers:
- name: lifecycle-hook-container
image: nginx

18. Explain Replication Controller


apiVersion: v1
kind: ReplicationController
metadata:
name: nginx-test
spec:
replicas: 2
selector:
app: nginx-test
template:
metadata:
name: nginx-test
labels:
app: nginx-test
spec:
containers:
- name: nginx-test
image: nginx
ports:
- containerPort: 80
19. Explain Replica Set
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: frontend
labels:
app: my-app
tier: frontend
spec:
# modify replicas according to your need
replicas: 2
selector:
matchLabels:
tier: frontend
matchExpressions:
- {key: tier, operator: In, values: [frontend]}
template:
metadata:
labels:
app: my-app
tier: frontend
spec:
containers:
- name: php-mysql
image: YOUR_IMG
env:
- name: SOME_VAR
value: VAL
ports:
- containerPort: 80
20. Kubernetes object management
Imperative commands - kubectl run nginx --image nginx
Imperative Object configuration - kubectl create -f [Link]
Declarative Object configuration – kubectl apply –f [Link]
21. Exercise
The following example creates a replica set and brings up two nginx pods.
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-test-deployment
labels:
app: nginx-test
spec:
replicas: 2
selector:
matchLabels:
app: nginx-test
template:
metadata:
labels:
app: nginx-test
spec:
containers:
- name: nginx-test
image: nginx:1.15
ports:
- containerPort: 80
To create the deployment execute,
kubectl apply -f <[Link]>
22. Fetch deployments by command
Kubectl get deploy
23. To Update the image
$ kubectl set image deployment <deplyoment name> <container-name>=nginx:1.9.1 –record
24. You can run kubectl rollout status <deployment name> to check status of rollout
25. Scaling Deployment
kubectl scale deployment <deployment name> --replicas=10
26. Pausing a Deployment
kubectl rollout pause deployment <deployment name>
27. Resume a Deployment
kubectl rollout resume deployment <deployment nm>
28. Exercise
Serivce for accessing pods with labels app: my-app with NodePort service type
kind: Service
apiVersion: v1
metadata:
name: my-test-service
spec:
selector:
app: my-app
ports:
- protocol: TCP
port: 80
targetPort: 8003
nodePort:30080
type: NodePort
29. Explain Stateful sets
30. Explain daemon sets
31. Deployments vs daemon sets
32. Explain cron job with an example
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: hello
spec:
schedule: "*/1 * * * *"
jobTemplate:
spec:
template:
spec:
containers:
- name: hello
image: busybox
args:
- /bin/sh
- -c
- date; echo Hello from the Kubernetes cluster
restartPolicy: OnFailure
33. You can view job creation by executing
kubectl get jobs --watch.
34. View printed message by executing
kubectl logs <pod-name>
35. Explain Ingress
36.

You might also like