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
Get nodes detail with verbose output
kubectl describe nodes my-node
26
Get pods detail with verbose output
kubectl describe pods my-pod
27
List Services Sorted by Name
kubectl get services --sort-by=.metadata.name
28
List pods Sorted by Restart Count
kubectl get pods --sort-by='.status.containerStatuses[0].restartCount'
29
List PersistentVolumes sorted by capacity
kubectl get pv --sort-by=.spec.capacity.storage
30
Get the version label of all pods with label app=cassandra
kubectl get pods --selector=app=cassandra -o jsonpath='{.items[*].metadata.labels.version}'
31
Retrieve the value of a key with dots, e.g. 'ca.crt'
kubectl get configmap myconfig -o jsonpath='{.data.ca\.crt}'
32
Get all worker nodes (use a selector to exclude results that have a label named 'node-role.kubernetes.io/master')
kubectl get node --selector='!node-role.kubernetes.io/master'
33
Get all running pods in the namespace
kubectl get pods --field-selector=status.phase=Running
34
Get ExternalIPs of all nodes
kubectl get nodes -o jsonpath='{.items[*].status.addresses[?(@.type=="ExternalIP")].address}'
35
List Events sorted by timestamp
kubectl get events --sort-by=.metadata.creationTimestamp
36
Show labels for all pods (or any other Kubernetes object that supports labelling)
kubectl get pods --show-labels
37
List all Secrets currently in use by a pod
kubectl get pods -o json | jq '.items[].spec.containers[].env[]?.valueFrom.secretKeyRef.name' | grep -v null | sort | uniq
38
Compares the current state of the cluster against the state that the cluster would be in if the manifest was applied.
kubectl diff -f ./my-manifest.yaml