Topic: Cluster Architecture, Installation & Configurationresources: etcd, namespace, podquestionTypes: how-to
Lab Environment:
master node: k8s-master
worker node: k8s-node-01
Take backup of etcd and store at /tmp/etcd-snapshot.db. You can use existing CA cert, Server cert and Server key configured for etcd.
* To view existing cert and key location, you can describe etcd pod in kube-system namespace
- A
ETCDCTL_API=3 etcdctl --endpoints=https://127.0.0.1:2379 \
--ca-cert=/etc/kubernetes/pki/etcd/ca.crt \
--server-cert=/etc/kubernetes/pki/etcd/server.crt \
--server-key=/etc/kubernetes/pki/etcd/server.key \
snapshot save /tmp/etcd-snapshot.db
- B
ETCDCTL_API=3 etcdctl --endpoints=https://127.0.0.1:2380 \
--cacert=/etc/kubernetes/pki/etcd/ca.crt \
--cert=/etc/kubernetes/pki/etcd/server.crt \
--key=/etc/kubernetes/pki/etcd/server.key \
snapshot save /tmp/etcd-snapshot.db
- C
ETCDCTL_API=3 etcdctl --endpoints=https://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 /tmp/etcd-snapshot.db
Show answer
Correct answer: C
Explanation: This command correctly takes a snapshot of the etcd database and saves it to the specified file. It uses the correct API version (3), the correct endpoint (2379), and specifies the CA certificate, server certificate, and server key for secure communication with etcd. The snapshot save command is the correct etcdctl subcommand for creating a snapshot.
Topic: Workloads & Schedulingresources: podquestionTypes: how-to
Lab Environment:
master node: k8s-master
worker node: k8s-node-01
Deploy a pod called limit-test with resource limit of 1 CPU and 256Mi of memory . Use image nginx.
- A
apiVersion: v1
kind: Pod
metadata:
labels:
run: limit-test
name: limit-test
spec:
containers:
- image: nginx
name: limit-test
resources:
requests:
cpu: "1"
memory: 256Mi
- B
kubectl run limit-test --image=nginx --limits='cpu=1,memory=256Mi'
- C
kubectl run limit-test --image=nginx --requests='cpu=1,memory=256Mi'
- D
apiVersion: v1
kind: Pod
metadata:
labels:
run: limit-test
name: limit-test
spec:
containers:
- image: nginx
name: limit-test
resources:
limits:
cpu: "1"
memory: 256Mi
Show answer
Correct answer: D
Explanation: This YAML definition correctly defines a Pod named limit-test using the nginx image and sets resource limits for CPU and memory. The resources section, specifically the limits subsection, is used to constrain the maximum amount of CPU and memory a container can use. This ensures that the pod does not consume more resources than allocated, preventing resource starvation for other pods in the cluster. The CPU limit is set to 1 core, and the memory limit is set to 256Mi (256 mebibytes).
Topic: Services & Networkingresources: network-policy, namespace, podquestionTypes: how-to
Lab Environment:
master node: k8s-master
worker node: k8s-node-01
Deploy a network policy called allow-only-namespace in webapp namespace. Make sure it allows ALL traffic ONLY from dev namespace.
Note:
1. Policy should NOT allow communication between pods in same namespace
2. Traffic ONLY from dev namespace is allowed on ALL ports
* Create necessary dependent resources
- A
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: allow-only-namespace
namespace: webapp
spec:
podSelector: {}
policyTypes: - Ingress
ingress:
- from:
- namespaceSelector:
matchLabels:
name: dev
- B
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: allow-only-namespace
namespace: webapp
spec:
podSelector: {}
policyTypes: - Ingress
ingress:
- from:
- namespaceSelector:
matchLabels:
name: dev
ports:
port: *
protocol: TCP
- C
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: allow-only-namespace
namespace: webapp
spec:
podSelector: {}
policyTypes: - Ingress
ingress:
- from:
- namespaceSelector:
matchLabels:
name: dev
- podSelector: {}
Show answer
Correct answer: A
Explanation: Ingress ingress: - from: - namespaceSelector: matchLabels: name: dev
This YAML defines a NetworkPolicy named allow-only-namespace in the webapp namespace. The podSelector: {} ensures that the policy applies to all pods in the webapp namespace. policyTypes: - Ingress specifies that this policy controls inbound traffic. The ingress section defines the rules for allowing traffic. The from section with namespaceSelector and matchLabels: name: dev allows traffic only from pods within a namespace labeled with name: dev. This correctly implements the requirement to allow all traffic only from the dev namespace to the webapp namespace.
Topic: Troubleshootingresources: nodequestionTypes: troubleshooting
Lab Environment:
master node: k8s-master
worker node: k8s-node-01
Worker node k8s-node-01 is in Not Ready state. Perform necessary steps to make k8s-node-01 available again.
- A
Check logs of kube proxy server:
kubectl logs -f-n kube-system Check logs from docker container:
docker ps -a | grep kube-proxy - It will returndocker logsRe-deploy kube API server if necessary
- B
SSH to node k8s-node-01 Check status of kubelet service:
systemctl status kubelet Check logs of kubelet service:
journalctl -u kubelet Fix the error as found in kubelet logs Start the kubelet service:
systemctl start kubelet
- C
Check logs of kube API server:
kubectl logs -f-n kube-system Check logs from docker container:
docker ps -a | grep kube-api - It will returndocker logsRe-deploy kube API server if necessary
Show answer
Correct answer: B
Explanation: This is the correct approach to troubleshoot a node in a NotReady state. The kubelet is the primary node agent that communicates with the Kubernetes control plane. When a node is NotReady, the kubelet is often the culprit. SSHing to the node allows direct inspection of the kubelet's status and logs. systemctl status kubelet reveals if the service is running and if there are any recent errors. journalctl -u kubelet provides a detailed log of the kubelet's activity, which is crucial for identifying the root cause of the problem. After identifying and fixing the issue (e.g., network connectivity problems, resource exhaustion, configuration errors), restarting the kubelet with systemctl start kubelet attempts to bring the node back into a Ready state.
Topic: Storageresources: persistent-volume, volumequestionTypes: how-to
Lab Environment:
master node: k8s-master
worker node: k8s-node-01
Create a PersistentVolume called pv-test with 8GB capacity. Set the access mode to ReadWriteMany. Any output from the container should be stored on the disk of underlying host at location /mnt/data.
- A
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv-test
spec:
capacity:
storage: 8Gi
accessModes: - ReadWriteMany
emptyDir: {}
- B
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv-test
spec:
capacity:
storage: 8Gi
accessModes: - ReadWriteMany
hostPath:
path: "/mnt/data"
- C
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv-test
spec:
capacity:
storage: 8Gi
accessModes: - ReadWriteMany
emptyDir:
path: "/mnt/data"
Show answer
Correct answer: B
Explanation: ReadWriteMany hostPath: path: "/mnt/data"
This is the correct answer because it defines a PersistentVolume (PV) named pv-test with a capacity of 8Gi, an access mode of ReadWriteMany, and uses hostPath to specify the directory on the host where the data will be stored. The hostPath volume type allows a PersistentVolume to use a directory on the node's filesystem. This configuration fulfills all the requirements of the question: creating a PV, setting its capacity, defining the access mode, and specifying the host path for storage.