kubectl Tips Flashcards

1
Q

command to show all commands

A

kubectl | more

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Enable command completion (autocomplete)

A

Kubectl source

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

true or false, command completion is always available after you enable it?

A

False: To enable command completion persistently you must add it to your .bash profile file

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Command to add command completion to your bash profile file

A

echo “source > ~/.bash_profile

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How to find CLI shortnames for resources

A

kubectl api-resources | more

second column will list shortname options.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How to find namespaces for pods?

A

Kubectl get pods –all-namespaces

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How to find namespaces for pods with a specified label?

A

Kubectl get pods –all-namespaces -L

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How to find namespaces for pods with a specified label and return only defined lables?

A

Kubectl get pods –all-namespaces -l
Explanation:
The -l is a lower case L instead of the uppercase. Lower case L will only return resources with defined labels, where upper case will return all, defined or not.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How to find namespaces for pods with a specified label and return only those with a specific label value

A

Kubectl get pods –all-namespaces -L -l =

Example:
Kubectl get pods –all-namespaces -L k8s-app -l k8s-app=kube-proxy

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How to find namespaces for pods with a specified label and return only those that do NOT match a specified value

A

Kubectl get pods –all-namespaces -L -l !=

Explanation
!= means “does not equal” and therefore returns all values that do not equal

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How to find namespaces for pods with a specified label and return based on multiple values

A

Join the values with commas.

ex. Kubectl get pods –all-namespaces -L -l !=,

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What command allows you to sort kubectl get returns?

A
  • -sort-by-

ex. kubctl get pods -n kube-system –sort-by=’{.metadata.creationTimestamp}’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

how can you generate a manifest file template using kubectl?

A

using the create command with -o yaml –dry-run

explanation
–dry-run will will not create resources but will instead showcase what would be created. When you output as yaml with -o yaml, a manifest file is generated and displayed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How can you create a manifest from existing resources?

A

use get and output ( -o ) to yaml.
example:
kubectl get pod -n kube-system jube-proxy-hwjjt -o yaml

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

When creating a manifest file from existing resources, how can you strip out cluster specific lines that you don’t want present in a generated manifest file?

A

add the –export option

example:
kubectl get pod -n kube-system jube-proxy-hwjjt -o yaml –export

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

what command will describe fields associated to API resources?

A

kubectl explain