kubectl commands Flashcards

1
Q

Show Merged kubeconfig settings

A

kubectl config view

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

Use multiple kubeconfig files at the same time

A

KUBECONFIG=~/.kube/config:~/.kube/kubconfig2

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

Get the password for the e2e user

A

kubectl config view -o jsonpath=’{.users[?(@.name == “e2e”)].user.password}’

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

Display list of contexts

A

kubectl config get-contexts

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

Display the current-context

A

kubectl config current-context

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

Set the default context to my-cluster-name

A

kubectl config use-context my-cluster-name

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

Add a new user to your kubeconf that supports basic auth

A

kubectl config set-credentials kubeuser/foo.kubernetes.com –username=kubeuser –password=kubepassword

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

Permanently save the namespace for all subsequent kubectl commands in that context

A

kubectl config set-context –current –namespace=ggckad-s2

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

Set a context utilizing a specific username and namespace

A

kubectl config set-context gce –user=cluster-admin –namespace=foo && kubectl config use-context gce

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

Delete user foo

A

kubectl config unset users.foo

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

Create resource(s)

A

kubectl apply -f ./my-manifest.yaml

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

Create from multiple files

A

kubectl apply -f ./my1.yaml -f ./my2.yaml

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

Create resource(s) in all manifest files in dir

A

kubectl apply -f ./dir

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

Create resource(s) from url

A

kubectl apply -f https://git.io/vPieo

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

Start a single instance of nginx

A

kubectl create deployment nginx –image=nginx

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

Get the documentation for pod manifests

A

kubectl explain pods

17
Q

List all services in the namespace

A

kubectl get services

18
Q

List all pods in all namespaces

A

kubectl get pods –all-namespaces

19
Q

List all pods in the current namespace, with more details

A

kubectl get pods -o wide

20
Q

List a particular deployment

A

kubectl get deployment my-dep

21
Q

List all pods in the namespace

A

kubectl get pods

22
Q

Get a pod’s YAML

A

kubectl get pod my-pod -o yaml

23
Q

Get nodes detail with verbose output

A

kubectl describe nodes my-node

24
Q

Get a pod’s YAML

A

kubectl get pod my-pod -o yaml

25
Q

Get nodes detail with verbose output

A

kubectl describe nodes my-node

26
Q

Get pods detail with verbose output

A

kubectl describe pods my-pod

27
Q

List Services Sorted by Name

A

kubectl get services –sort-by=.metadata.name

28
Q

List pods Sorted by Restart Count

A

kubectl get pods –sort-by=’.status.containerStatuses[0].restartCount’

29
Q

List PersistentVolumes sorted by capacity

A

kubectl get pv –sort-by=.spec.capacity.storage

30
Q

Get the version label of all pods with label app=cassandra

A

kubectl get pods –selector=app=cassandra -o jsonpath=’{.items[*].metadata.labels.version}’

31
Q

Retrieve the value of a key with dots, e.g. ‘ca.crt’

A

kubectl get configmap myconfig -o jsonpath=’{.data.ca.crt}’

32
Q

Get all worker nodes (use a selector to exclude results that have a label named ‘node-role.kubernetes.io/master’)

A

kubectl get node –selector=’!node-role.kubernetes.io/master’

33
Q

Get all running pods in the namespace

A

kubectl get pods –field-selector=status.phase=Running

34
Q

Get ExternalIPs of all nodes

A

kubectl get nodes -o jsonpath=’{.items[*].status.addresses[?(@.type==”ExternalIP”)].address}’

35
Q

List Events sorted by timestamp

A

kubectl get events –sort-by=.metadata.creationTimestamp

36
Q

Show labels for all pods (or any other Kubernetes object that supports labelling)

A

kubectl get pods –show-labels

37
Q

List all Secrets currently in use by a pod

A

kubectl get pods -o json | jq ‘.items[].spec.containers[].env[]?.valueFrom.secretKeyRef.name’ | grep -v null | sort | uniq

38
Q

Compares the current state of the cluster against the state that the cluster would be in if the manifest was applied.

A

kubectl diff -f ./my-manifest.yaml