CKA MOCK QS-1
- RNREDDY

- Aug 7
- 1 min read
Updated: Aug 25

Q-1
Solve this question on: ssh cka9412
You're asked to extract the following information out of kubeconfig file /opt/course/1/kubeconfig on cka9412:
1. Write all kubeconfig context names into /opt/course/1/contexts, one per line
2. Write the name of the current context into /opt/course/1/current-context
3. Write the client-certificate of user account-0027 base64-decoded into /opt/course/1/cert
Solution:
To solve this task on the server cka9412, follow these steps after connecting via SSH:
Step 1: SSH into the server
ssh cka9412
Step 2: Set environment variable for kubeconfig
kubectl config get-contexts -o name > /opt/course/1/contexts
Step 3: Write all context names to /opt/course/1/contexts
kubectl config get-contexts -o name > /opt/course/1/contexts
Step 4: Write the current context to /opt/course/1/current-context
kubectl config current-context > /opt/course/1/current-context
Step 5: Extract and decode client-certificate for account-0027
We'll use yq or grep/jq if yq isn't installed. Here's both ways:
Using yq (preferred if available):
yq '.users[] | select(.name == "account-0027") | .user["client-certificate-data"]' /opt/course/1/kubeconfig | tr -d '"' | base64 -d > /opt/course/1/cert
If yq not available, use grep + jq method:
CLIENT_CERT=$(grep -A10 "name: account-0027" /opt/course/1/kubeconfig | grep client-certificate-data | awk '{print $2}')
echo "$CLIENT_CERT" | base64 -d > /opt/course/1/cert
Step 6: Verify files
cat /opt/course/1/contexts
cat /opt/course/1/current-context
ls -l /opt/course/1/cert



Comments