본문 바로가기

클라우드/CKA

[CKA] Advanced kubectl commands

문제01

Get the list of nodes in JSON format and store it in a file at /opt/outputs/nodes.json.

[나의 풀이]

kubectl get nodes -o json > /opt/outputs/nodes.json

 

문제02

Get the details of the node node01 in json format and store it in the file /opt/outputs/node01.json.

[나의 풀이]

kubectl get nodes node01 -o json > /opt/outputs/node01.json

 

문제03

Use JSON PATH query to fetch node names and store them in /opt/outputs/node_names.txt.

Remember the file should only have node names.

[나의 풀이]

kubectl get nodes -o=jsonpath='{.items[*].metadata.name}' > /opt/outputs/node_names.txt

 

문제04

Use JSON PATH query to retrieve the osImages of all the nodes and store it in a file /opt/outputs/nodes_os.txt.

The osImages are under the nodeInfo section under status of each node.

[나의 풀이]

kubectl get nodes -o=jsonpath='{.items[*].status.nodeInfo.osImage}' > /opt/outputs/nodes_os.txt

 

문제 05

A kube-config file is present at /root/my-kube-config. Get the user names from it and store it in a file /opt/outputs/users.txt.

Use the command kubectl config view --kubeconfig=/root/my-kube-config to view the custom kube-config.

[나의 풀이]
kubectl config view --kubeconfig=/root/my-kube-config -o jsonpath='{.users[*].name}' > /opt/outputs/users.txt

 

문제06

A set of Persistent Volumes are available. Sort them based on their capacity and store the result in the file /opt/outputs/storage-capacity-sorted.txt.

[나의 풀이]

kubectl get pv -A --sort-by=.spec.capacity.storage > /opt/outputs/storage-capacity-sorted.txt

 

문제07

That was good, but we don't need all the extra details. Retrieve just the first 2 columns of output and store it in /opt/outputs/pv-and-capacity-sorted.txt.

The columns should be named NAME and CAPACITY. Use the custom-columns option and remember, it should still be sorted as in the previous question.

[나의 풀이]

kubectl get pv -A --sort-by=.spec.capacity.storage -o=custom-columns='NAME:metadata.name,CAPACITY:spec.capacity.storage' > /opt/outputs/pv-and-capacity-sorted.txt

문제08

Use a JSON PATH query to identify the context configured for the aws-user in the my-kube-config context file and store the result in /opt/outputs/aws-context-name.

[정답]

kubectl config view --kubeconfig=/root/my-kube-config -o jsonpath='{.contexts[?(@.context.user=="aws-user")].name}' > /opt/outputs/aws-context-name

 

'클라우드 > CKA' 카테고리의 다른 글

[CKA] 네트워크 & 리눅스 명령어  (0) 2022.01.16
[CKA] Advanced kubectl commands  (0) 2022.01.03
[CKA] Ligtning Lab  (0) 2022.01.02
[CKA] mock exam 03  (0) 2021.12.26
[CKA] mock exam 02  (0) 2021.12.26
[CKA] mock exam 01  (0) 2021.12.15