K8s Object Management Flashcards
What is kubectl?
kubectl is a command line tool that allows you to interact with Kubernetes. Kubectl uses the Kubernetes API to communicate with the cluster and carry out your commands.
“You can use kubectl to deploy applications, inspect and manage cluster resources, and view logs.”
What does ‘kubectl get’ do?
‘kubectl get’ is used to list objects in the Kubernetes cluster.
$ kubectl get <object-type> <object-name> -o <output> --sort-by <JSONPath> --selector <selector></selector></JSONPath></output></object-name></object-type>
- -o : Set output format
- –sort-by : Sort the output using JSONPath expression
- –selector : Filter results by label
What does ‘kubectl describe’ do?
‘kubectl describe’ allows you to get detailed information about Kubernetes objects.
$ kubectl describe <object-type> <object-name></object-name></object-type>
What does ‘kubectl delete’ do?
‘kubectl delete’ is used to delete objects from the cluster.
$ kubectl delete <object-type> <object-name></object-name></object-type>
What does ‘kubectl create’ do?
‘kubectl create’ allows you to create Kubernetes objects.
$ kubectl create -f <file-name></file-name>
Supply a YAML file with -f to create an object from a YAML descriptor stored in the file.
**Note: If you attempt to create an object that already exists, an error will occur.
What does ‘kubectl apply’ do?
‘kubectl apply’ is similar to ‘kubectl create.’ However, if you use ‘kubectl apply’ on an existing object, it will modify the existing object, if possible.
$ kubectl apply -f <file-name></file-name>
What does ‘kubectl exec’ do?
‘kubectl exec’ is used to run commands inside containers.
Keep in mind that in order for a command to succeed, the necessary software must exist within the container to run it.
$ kubectl exec <pod-name> -- <command></command></pod-name>
**For pods with multiple containers:
$ kubectl exec <pod-name> -c <container-name> -- <command></command></container-name></pod-name>
What does this command do?
$ kubectl get pods -o wide –sort-by .spec.nodeName
Allows you to see which pods are running on which node.
What is RBAC in K8s?
Role-based access control (RBAC) in K8s allows you to control what users are allowed to do and access within your cluster
For example, you can use RBAC to allow developers to read metadata and logs from K8s pods but not make changes to them.
What is the Kubernetes Metrics Server?
In order to view metrics about the resources pods and containers are using, we need an add-on to collect and provide the data. One such add-on is Kubernetes Metrics Server.
What is ‘kubectl top’ ?
With kubectl top, you can view data about resource usage in your pods and nodes.
Kubectl top also supports flags like –sort-by and selector
$ kubectl top pod –sort-by <JSONPath> --selector <selector></selector></JSONPath>
How would you enable the Kubernetes Metrics Server add-on?
kubectl apply -f https://ram.githubusercontent.com/linuxacademy/content-cka-resources/master/metrics-server-components.yaml
Query the metrics server api?
$ kubectl get –raw /apis/metrics.k8s.io/
Check CPU usage of the pods in a cluster, sorted by the ones using the most CPU.
$ kubectl top pod –sort-by cpu
Check the resource usage of a pod based on a label called ‘metrics-test’
$ kubectl top pod –selector app=metrics-test
Check resource usage by node.
kubectl top node
Which flag allows you to save the command that was used to make a change?
A. –save-command
B. –record
C. –log
D. –dry-run
B. –record
Which flag allows you to see what would happen when creating an object without actually creating the object?
A. -o test
B. –record
C. –dry-run=client
D. –test
C. –dry-run=client
Which Kubernetes object defines a set of permissions and exists outside of any Namespace?
A. Role
B. ClusterRole
C. RBAC
D. ClusterRoleBinding
B. ClusterRole
Which Kubernetes object can apply a Role to a user or ServiceAccount, but only within a particular Namespace?
A. NetworkPolicy
B. ClusterRoleBinding
C. ClusterRole
D. RoleBinding
D. RoleBinding
When using kubectl get, which flag allows you to filter results by label?
A. –sort-by
B. –filter-by
C. –label
D. –selector
D. –selector
Which flag allows you to save the command that was used to make a change?
A. –record
B. –save-command
C. –log
D. –dry-run
A. –record
Which Kubernetes object can apply a Role to a user or ServiceAccount, but only within a particular Namespace?
A. RoleBinding
B. ClusterRole
C. NetworkPolicy
D. ClusterRoleBinding
A. RoleBinding
Which tool collects data about resource usage by each container/Pod?
A. Metrics Server
B. Resource Inspector
C. API Server
D. Kubernetes Scheduler
A. Metrics Server
Which command can be used to display resource usage data for Pods?
A. kubectl top
B. kubectl metrics
C. kubectl usage
D. kubectl cpu
A. kubectl top
Which flag allows you to see what would happen when creating an object without actually creating the object?
A. –record
B. –test
C. -o test
D. –dry-run=client
D. –dry-run=client
When using kubectl get, which flag allows you to filter results by label?
A. –sort-by
B. –selector
C. –label
D. –filter-by
B. –selector
Which Kubernetes object defines a set of permissions and exists outside of any Namespace?
A. Role
B. ClusterRole
C. RBAC
D. ClusterRoleBinding
B. ClusterRole
How can you assign permissions to ServiceAccounts?
A. ServiceAccountRole
B. PodSecurityPolicies
C. RBAC
D. NetworkPolicies
C. RBAC
Which command shows detailed information about a Kubernetes object in a human-readable format?
A. kubectl get -o readable
B. kubectl describe
C. kubectl get -o describe
D. kubectl view
B. kubectl describe
What object allows you to create an account used by Pods to access the Kubernetes API?
A. Role
B. ServiceAccount
C. Principal
D. User
B. ServiceAccount
QUESTION 1
Which of the following situations could init containers be used for? (select all that apply)
Choose 3
A. Perform startup steps involving sensitive data outside the main container(s).
B. Put data into a shared volume so that the main container(s) can access it.
C. Interact with the main container during runtime.
D. Make a Pod wait for another resource to be available before finishing startup.
A. Perform startup steps involving sensitive data outside the main container(s).
B. Put data into a shared volume so that the main container(s) can access it.
D. Make a Pod wait for another resource to be available before finishing startup.
Which object should you use to store non-sensitive configuration data?
A. ClusterRole
B. ConfigMap
C. Secret
D. Pod
B. ConfigMap
What does a resource request do (select all that apply)?
Choose 2
A. Throttles containers attempting to use more than the requested resources.
B. Stops a container that is using more than the requested resources.
C. Allows you to define the amount of resources you expect a container to use.
D. Prevents Pods from being scheduled on Nodes without sufficient resources.
C. Allows you to define the amount of resources you expect a container to use.
D. Prevents Pods from being scheduled on Nodes without sufficient resources.
What object should you use to store a password?
A. SecureConfigMap
B. ConfigMap
C. Secret
D. Password
C. Secret