We are committed to provide service 24 X 7

Deals, Shopping, Training, Tools

26
2.170.624,55

Cart

Learn how to – Kubectl Cheat Sheet for Kubernetes Admins & CKA Exam Prep

Learn how to – Kubectl Cheat Sheet for Kubernetes Admins & CKA Exam Prep.

This is an opinionated cheat sheet created to serve as a reference point for daily Kubernetes operations and administration done on the command line interface with kubectl. If you are preparing for CKA or CKAD exams, the cheat sheet contains commands that will hep you to quickly complete exam tasks. For exam preparation don’t rely entirely on this document but rather go through the course content with lots of practice.

If you have that time saver kubectl command that we’ve missed out in this post don’t hesitate to drop it in the comments section. We’ll be happy to update the document any time.

We’ll start with the helpful generic commands before covering task specific commands used in Administration and Applications deployment in Kubernetes or an OpenShift Cluster.

Kubernetes installation guides:

Helpful commands for general use

Below are some of the most helpful general use commands when working with Kubernetes.

# Display Kubernetes API Server URL
$ kubectl cluster-info

# Dump all cluster information
$ kubectl cluster-info dump

# Get kubeadm config
$ kubectl -n kube-system get configmap kubeadm-config -o yaml

# List all nodes in the cluster
$ kubectl get nodes

# Check health of cluster components
$ kubectl get componentstatuses
$ kubectl get cs

# List all API resources
$ kubectl api-resources

# List API versions
$ kubectl api-versions

1. Install kubectl

This is how to install kubectl on Linux and macOS:

Linux

curl -LO "https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl"
chmod +x ./kubectl
sudo mv ./kubectl /usr/local/bin/kubectl

macOS:

curl -LO "https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/darwin/amd64/kubectl"
chmod +x ./kubectl
sudo mv ./kubectl /usr/local/bin/kubectl

Confirm installation by checking version:

$ kubectl version --client
Client Version: version.Info{Major:"1", Minor:"27", GitVersion:"v1.27.2", GitCommit:"7f6f68fdabc4df88cfea2dcf9a19b2b830f1e647", GitTreeState:"clean", BuildDate:"2023-05-17T14:20:07Z", GoVersion:"go1.20.4", Compiler:"gc", Platform:"linux/amd64"}
Kustomize Version: v5.0.1

2. Enable Bash Completion

By default Bash completion is not enabled after installation of kubectl command. Enable it with the commands below.

Bash:

echo 'source <(kubectl completion bash)' >>~/.bashrc
source ~/.bashrc

zsh:

echo 'source <(kubectl completion zsh) >> ~/.zshrc
source ~/.zshrc

3. List and Switch context

A context is a group of access parameters. Each context contains a Kubernetes cluster, a user, and a namespace.

Listing contexts:

kubectl config get-contexts

Switch between clusters by setting the current-context in a kubeconfig file:

kubectl config use-context <context-name>

Set a context entry in kubeconfig:

kubectl config set-context <context-name>

If you want to change namespace preference use:

kubectl config set-context <context-name> --namespace=<ns-name>

See current context:

 kubectl config current-context

Switch to a namespace using current context

 kubectl config set-context --current --namespace <ns-name>

4. Validate manifest yaml file syntax

If you’ve created a deployment yaml file and would like to validate the syntax, use the command:

 kubectl create --dry-run --validate -f <file>.yaml

Example:

$ kubectl create --dry-run=client --validate -f hello-world.yml
pod/hello-world created (dry run)

If there is a syntax errors you’ll get from output:

error: error parsing hello-world.yml: error converting YAML to JSON: yaml: line 12: did not find expected '-' indicator

5. Drain a node while removing local data

A node can be drained and the local data used by running containers cleared as well. For this the command syntax is:

kubectl drain <node-name> --ignore-daemonsets=true --delete-local-data=true

To force drain you can add the --force flag though this is not recommended.

6. Apply yaml files and folders

You can use apply argument to apply a configuration to a resource by filename or stdin. The command syntax is:

kubectl apply -f <file-name>.yaml
# Or for json:
kubectl apply -f <file-name>.json

For folder with a number of yaml fils, use:

kubectl apply -R -f . # If files are in current working directory

With absolute path:

kubectl apply -R -f /path/to/yaml/files

7. Create time saving aliases

You can also create some aliases that make your command line usage much faster.

$ vim ~/.bashrc
# kubectl alias
alias k='kubectl'

# Create resources
alias kcf='kubectl create -f'
alias kaf='kubectl apply -f'

# List resources
alias kgp='kubectl get pods'
alias kgpa='kubectl get pods --all-namespaces'
alias kgd='kubectl get deployments'
alias kgs='kubectl get service'
alias kgh='kubectl get hpa'

# Delete resources
alias kd='kubectl delete'
alias kdp='kubectl delete pods'
alias kdd='kubectl delete deployments'
alias kgs='kubectl delete service'

8. Start a temporary pod that dies on exit

You can quickly create a temporary pod with shell session for testing purposes that is destroyed once you exit.

kubectl run --rm -it --image=<image> <podname> -- sh

Example:

$ kubectl run --rm -it --image=alpine alpine -- sh
If you don't see a command prompt, try pressing enter.
/ # apk update
fetch https://dl-cdn.alpinelinux.org/alpine/v3.18/main/x86_64/APKINDEX.tar.gz
fetch https://dl-cdn.alpinelinux.org/alpine/v3.18/community/x86_64/APKINDEX.tar.gz
v3.18.0-539-g98821b89481 [https://dl-cdn.alpinelinux.org/alpine/v3.18/main]
v3.18.0-538-geebfeed6b97 [https://dl-cdn.alpinelinux.org/alpine/v3.18/community]
OK: 20067 distinct packages available

/ # apk add wget curl vim
(1/14) Installing ca-certificates (20230506-r0)
(2/14) Installing brotli-libs (1.0.9-r14)
(3/14) Installing libunistring (1.1-r1)
(4/14) Installing libidn2 (2.3.4-r1)
(5/14) Installing nghttp2-libs (1.53.0-r0)
(6/14) Installing libcurl (8.1.2-r0)
(7/14) Installing curl (8.1.2-r0)
(8/14) Installing vim-common (9.0.1568-r0)
(9/14) Installing xxd (9.0.1568-r0)
(10/14) Installing ncurses-terminfo-base (6.4_p20230506-r0)
(11/14) Installing libncursesw (6.4_p20230506-r0)
(12/14) Installing vim (9.0.1568-r0)
(13/14) Installing pcre2 (10.42-r1)
(14/14) Installing wget (1.21.4-r0)
Executing busybox-1.36.0-r9.trigger
Executing ca-certificates-20230506-r0.trigger
OK: 43 MiB in 29 packages

/ # curl google.com
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="http://www.google.com/">here</A>.
</BODY></HTML>

/ # exit
Session ended, resume using 'kubectl attach alpine -c alpine -i -t' command when the pod is running
pod "alpine" deleted

$ kubectl get pods
NAME     READY   STATUS        RESTARTS   AGE
alpine   0/1     Terminating   0          80s

9. Create a namespace

A namespace is created with the command:

kubectl create namespace <namespace-name>

Or

kubectl create ns <namespace-name>

To switch to the namespace for all operations use:

kubectl config get-contexts
kubectl config set-context <context-name> --namespace=<namespace-name>

Examples:

$ kubectl create ns dev
namespace/dev created

$ kubectl get ns dev -o yaml
apiVersion: v1
kind: Namespace
metadata:
  creationTimestamp: "2023-06-05T10:34:06Z"
  labels:
    kubernetes.io/metadata.name: dev
  name: dev
  resourceVersion: "54914669"
  uid: e7cec333-32fa-4f0b-9fd5-ebd31d3a2e85
spec:
  finalizers:
  - kubernetes
status:
  phase: Active

To delete namespace run:

$ kubectl delete ns dev
namespace "dev" deleted

10. Run shell command in a Pod without tty

Let’s create a pod that runs in the background.

cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Pod
metadata:
  name: ubuntu
  labels:
    app: ubuntu
spec:
  containers:
  - name: ubuntu
    image: ubuntu:latest
    command: ["/bin/sleep", "3650d"]
    imagePullPolicy: IfNotPresent
  restartPolicy: Always
EOF

Confirm Pod is running:

$ kubectl get pods ubuntu
NAME     READY   STATUS    RESTARTS   AGE
ubuntu   1/1     Running   0          14s

Starting shell session to the Pod:

$ kubectl exec --stdin --tty ubuntu -- sh
# exit

$ kubectl exec --stdin --tty ubuntu -- /bin/bash
root@ubuntu:/# exit
exit

Running command directly in the container without tty.

$ kubectl exec -it ubuntu -- ls -l /etc/hosts
-rw-r--r-- 1 root root 205 Dec 10 08:25 /etc/hosts

$ kubectl exec -it ubuntu -- apt update
kubectl exec -ti busybox -- nslookup <Pod-ip>

$ kubectl exec -it ubuntu -- cat /etc/os-release
NAME="Ubuntu"
VERSION="20.04.1 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.1 LTS"
VERSION_ID="20.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal

Kill Pod.

$ kubectl delete pod ubuntu
pod "ubuntu" deleted

11. Check environment variables in a Pod

To list all environment variables in a Pod use the command:

$ kubectl exec <pod> -- env

Example

$ kubectl exec ubuntu -- env
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=ubuntu
KUBERNETES_PORT_443_TCP_ADDR=172.20.0.1
KUBERNETES_SERVICE_HOST=172.20.0.1
KUBERNETES_SERVICE_PORT=443
KUBERNETES_SERVICE_PORT_HTTPS=443
KUBERNETES_PORT=tcp://172.20.0.1:443
KUBERNETES_PORT_443_TCP=tcp://172.20.0.1:443
KUBERNETES_PORT_443_TCP_PROTO=tcp
KUBERNETES_PORT_443_TCP_PORT=443
HOME=/root

12. Get explanation of resource usage

The command syntax is:

kubectl explain <resource>

Examples:

kubectl explain pods
kubectl explain deploy
kubectl explain service

Explain fields.

kubectl explain deploy.spec
kubectl explain deploy.spec.replicas
kubectl explain pod.metadata.namespace

13. Get resources sorted by name

To list resources sorted by name you’ll use.

kubectl get <resource> --sort-by=.metadata.name

Examples.

$ kubectl get pods --sort-by=.metadata.name
NAME     READY   STATUS    RESTARTS   AGE
ubuntu   1/1     Running   0          10m

$ kubectl get svc --sort-by=.metadata.name --all-namespaces
NAMESPACE     NAME         TYPE        CLUSTER-IP    EXTERNAL-IP   PORT(S)         AGE
kube-system   kube-dns     ClusterIP   172.20.0.10   <none>        53/UDP,53/TCP   2d11h
default       kubernetes   ClusterIP   172.20.0.1    <none>        443/TCP         2d11h

14. Generate a Pod manifest YAML file

You can use kubectl run to generate a yaml manifest file for Pods deployment.

Command help page.

kubectl run pod --help

The following command prints the corresponding API objects without creating them:

kubectl run nginx --image=nginx --restart=Never --dry-run=client -o yaml

With memory and CPU Limits:

kubectl run nginx --image=nginx --restart=Never --limits='cpu=300m,memory=512Mi' --dry-run=client -o yaml

With both CPU and Memory requests and Limits.

kubectl run nginx --image=nginx --restart=Never --requests='cpu=100m,memory=256Mi' --limits='cpu=300m,memory=512Mi' --dry-run=client -o yaml

You can direct the output to a file.

kubectl run nginx --image=nginx --restart=Never --dry-run=client -o yaml >nginx-pod.yaml

You can then create the Pod by applying the file.

$ kubectl apply -f ./nginx-pod.yaml
pod/nginx created

Confirm Pod is running:

$ kubectl get pod nginx
NAME    READY   STATUS    RESTARTS   AGE
nginx   1/1     Running   0          31s

Delete Pod.

$ kubectl delete pod nginx
pod "nginx" deleted

15. Generate a Deployment deployment YAML file

Similar generation commands applies for deployments resource types. Only that we don’t pass –restart=Never.

kubectl create deploy nginx --image=nginx  --replicas=3 --dry-run=client -o yaml

Write to file

kubectl create deploy nginx --image=nginx  --replicas=3 --dry-run=client -o yaml >nginx-deployment.yml

You can the modify the file and apply resource creations.

$ kubectl apply -f nginx-deployment.yml
deployment.apps/nginx created

Check deployment.

$ kubectl get deploy nginx
NAME    READY   UP-TO-DATE   AVAILABLE   AGE
nginx   3/3     3            3           37s

List Pods matching Nginx.

$  kubectl get pods -l app=nginx
NAME                    READY   STATUS    RESTARTS   AGE
nginx-f89759699-6hcng   1/1     Running   0          70s
nginx-f89759699-dvqhf   1/1     Running   0          70s
nginx-f89759699-hgbtq   1/1     Running   0          70s

Remove deployment.

$ kubectl delete deploy nginx
deployment.apps "nginx" deleted

16. Expose Pod or Deployment on a Service

Use kubectl expose command to make a deployment or Pods exposed on ClusterIP or NodePort.

$ kubectl expose -h

See example below.

$ kubectl expose deployment nginx --port=80 --type=ClusterIP
service/nginx exposed

$ kubectl get svc nginx
NAME    TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)   AGE
nginx   ClusterIP   172.20.29.63   <none>        80/TCP    17s

Supported types for the service: ClusterIP, NodePort, LoadBalancer, or ExternalName.

$ kubectl expose deployment nginx --port=80 --type=NodePort
$ kubectl get svc nginx
NAME    TYPE       CLUSTER-IP     EXTERNAL-IP   PORT(S)        AGE
nginx   NodePort   172.20.32.97   <none>        80:30292/TCP   3s

This other example creates a service for a pod redis, which serves on port 6379 with the name “redis”

kubectl expose pod redis --port=6379 --name=redis

You can also manually specify the Port exposed by the container(Application port).

kubectl expose pod redis  --type=ClusterIP --port=6379 --target-port=6379

17. Scale up pods in a deployment

You can scale up the number of Pods in a deployment without editing any file.

$ kubectl get deploy
NAME    READY   UP-TO-DATE   AVAILABLE   AGE
nginx   3/3     3            3           7h

$ kubectl scale --replicas=4 deployment nginx
deployment.apps/nginx scaled

$ kubectl get deploy
NAME    READY   UP-TO-DATE   AVAILABLE   AGE
nginx   4/4     4            4           7h3m

$ kubectl get pods -l app=nginx
NAME                    READY   STATUS    RESTARTS   AGE
nginx-f89759699-7x7q7   1/1     Running   0          2m21s
nginx-f89759699-jz9cj   1/1     Running   0          7h3m
nginx-f89759699-nm2nk   1/1     Running   0          7h3m
nginx-f89759699-ppdzr   1/1     Running   0          7h3m

$ kubectl scale --replicas=3 deployment nginx
deployment.apps/nginx scaled

$ kubectl get deploy
NAME    READY   UP-TO-DATE   AVAILABLE   AGE
nginx   3/3     3            3           7h4m

18. Migrate all Pods in a node and make it Unschedulable

Identify node to action on:

kubectl get nodes

Next, tell Kubernetes to drain the node:

kubectl drain <node-name>

You may need to ignore daemonsets and delete local container data.

kubectl drain  <node-name> --delete-local-data --ignore-daemonsets

Tell Kubernetes to stop scheduling new pods onto the node:

kubectl cordon <node-name>

To resume scheduling on the node use command:

kubectl uncordon <node-name>

19. Create Multiple containers in a Pod

First generate Pod manifest file. We’ll create pod called mypod with ubuntu image.

kubectl run mypod --image=nginx --restart=Never --dry-run=client -o yaml >mypod.yaml

Edit the file and add other containers to the named Pod.

$ vim mypod.yaml
apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: null
  labels:
    run: mypod
  name: mypod
spec:
  containers:
  - image: nginx
    name: mypod
    resources: {}
  dnsPolicy: ClusterFirst
  restartPolicy: Never
status: {}

We’ve added two containers – nginx and redis. To apply configurations run the command:

$ kubectl apply -f mypod.yaml
pod/mypod created

Confirm the pod has two containers.

$ kubectl get pod mypod
NAME    READY   STATUS    RESTARTS   AGE
mypod   2/2     Running   0          39s

Clean up:

$ kubectl delete -f mypod.yaml
pod "mypod" deleted

20. Create Service Account, Role and Roledinding

Create service called demo.

$ kubectl create sa demo
serviceaccount/demo created

Create a role named demo that allows user to perform “get”, “watch” and “list” on pods,deploy,ds,rs,sts:

$ kubectl create role demo --verb=get,list,watch --resource=pods,deploy,ds,rs,sts
role.rbac.authorization.k8s.io/demo created

# All verbs
$ kubectl create clusterrole demo --verb='*' --resource=pods,deploy,ds,rs,sts

# For cluster role
$ kubectl create clusterrole demo --verb=get,list,watch --resource=pods,deploy,ds,rs,sts
clusterrole.rbac.authorization.k8s.io/demo created

Create a RoleBinding for the demo role.

$ kubectl create rolebinding demo --role=demo --user=demo
rolebinding.rbac.authorization.k8s.io/demo created

# For Cluster role
$ kubectl create rolebinding demo --clusterrole==demo --user=demo

# Clusterrole binding
$ kubectl create clusterrolebinding demo-admin --clusterrole=demo --user=demo

Confirm:

$ kubectl get sa,role,rolebinding
NAME                      SECRETS   AGE
serviceaccount/default    1         2d21h
serviceaccount/demo       1         4m48s
serviceaccount/newrelic   1         3h51m

NAME                                  CREATED AT
role.rbac.authorization.k8s.io/demo   2020-12-10T19:09:01Z

NAME                                         ROLE        AGE
rolebinding.rbac.authorization.k8s.io/demo   Role/demo   21s

Validate:

kubectl auth can-i create deployment --as demo # yes
kubectl auth can-i '*' ds --as demo # yes

Clean up:

kubectl delete sa demo
kubectl delete role demo
kubectl delete clusterrole demo
kubectl delete rolebinding demo

21. Get Logs on Pod(s)

Get recent logs on a named Pod:

$ kubectl get pods
NAME                    READY   STATUS    RESTARTS   AGE
newrelic-infra-hp8dt    1/1     Running   0          3h57m
newrelic-infra-r4bpg    1/1     Running   0          3h57m
nginx-f89759699-jz9cj   1/1     Running   0          8h
nginx-f89759699-nm2nk   1/1     Running   0          8h
nginx-f89759699-ppdzr   1/1     Running   0          8h
ubuntu                  1/1     Running   0          10h

$ kubectl logs newrelic-infra-r4bpg

Follow logs stream in realtime.

$ kubectl logs newrelic-infra-r4bpg -f

Get recent logs from all Pods in a deployment:

$ kubectl get deployments
NAME    READY   UP-TO-DATE   AVAILABLE   AGE
nginx   3/3     3            3           8h

$ kubectl logs deploy/nginx
$ kubectl logs deploy/nginx -f

Use regex to extract logs.

$ kubectl logs newrelic-infra-r4bpg | grep 'connect got id'
time="2020-12-10T15:19:37Z" level=info msg="connect got id" agent-guid=MjU4Mjg0NXxJTkZSQXxOQXw0NDQ3ODMzNDM1Nzk0NDYyMjgx agent-id=4447833435794462281 component=IdentityConnectService

Write output to a file:

kubectl logs newrelic-infra-r4bpg | grep 'connect got id' > logs.txt

Print the logs for the previous instance of the container in a pod if it exists

kubectl logs <pod-name> --previous

22. Get top pods

For this you need Metrics server deployed in your cluster. See below:

Get top resource utilization pods.

kubectl top pod

Get top pods with high cpu utilization:

kubectl top pod --sort-by='cpu'

Filter using labels.

$ kubectl top pod -l 'app=nginx' --sort-by='cpu'
NAME                    CPU(cores)   MEMORY(bytes)
nginx-f89759699-jz9cj   0m           2Mi
nginx-f89759699-nm2nk   0m           2Mi
nginx-f89759699-ppdzr   0m           2Mi

Get only one pod with highest CPU usage and write output to file.

kubectl top pod -l 'app=nginx' --sort-by='cpu' | awk 'NR==2{print $1}'
kubectl top pod -l 'app=nginx' --sort-by='cpu' | awk 'NR==2{print $1}' >top_cpu.txt

23. Roll out and roll back deployment

Deploy Nginx container.

$ kubectl create deploy web --replicas=2 --image=nginx:1.24.0
deployment.apps/web created

$ kubectl get deploy web
NAME   READY   UP-TO-DATE   AVAILABLE   AGE
web    2/2     2            2           16s

Update deployment to use nginx image version 1.25.0

# Syntax: $ kubectl set image CONTAINER_NAME_1=CONTAINER_IMAGE_1 ... CONTAINER_NAME_N=CONTAINER_IMAGE_N
$ kubectl set image deployment web nginx=nginx:1.25.0 --record
deployment.apps/web image updated

Check rollout status

$ kubectl rollout status deployment/web
deployment "web" successfully rolled out

View the rollout history of a deployment:

$ kubectl rollout history deployment/web
deployment.apps/web
REVISION  CHANGE-CAUSE
1         kubectl set image deployment web nginx=nginx:1.25.0 --record=true

To check Pods use:

$ kubectl get  pods
NAME                   READY   STATUS    RESTARTS   AGE
web-684f57c5cb-h2mqb   1/1     Running   0          44s
web-684f57c5cb-q56wx   1/1     Running   0          47s

You can check image version of the containers:

$ kubectl get deploy web -o jsonpath="{..image}";echo
nginx:1.25.0

If you want to rollback to the previous deployment, use the commands below:

$ kubectl rollout undo deployment web
deployment.apps/web rolled back

Rolling out to particular revision

kubectl rollout undo deployment/web --to-revision=3

24. Label Node and Assign Pods to Nodes

How to add labels to a Node.

kubectl label nodes <node-name> <label-key>=<label-value>

Example:

kubectl label nodes k8snode01 disktype=ssd

You can then assign Pods to the Nodes.

spec:
  containers:
  - name: nginx
    image: nginx
    imagePullPolicy: IfNotPresent
  nodeSelector:
    disktype: ssd

25. Copy files to and from Pods

The kubectl cp commands can be used to copy files into a Pod or from Pods.

kubectl cp --help

In this example we’ll copy files from a Pod to our local system.

$ kubectl exec -ti mypod1 -- ls
bin  boot  dev	dump_ops_in_flight.txt	etc  home  lib	lib64  lost+found  media  mnt  opt  proc  root	run  sbin  session_ls.txt  srv	sys  tmp  usr  var

$ kubectl cp mypod1:/dump_ops_in_flight.txt dump_ops_in_flight.txt
tar: Removing leading `/' from member names

$ kubectl cp mypod1:/dump_ops_in_flight.txt session_ls.txt
tar: Removing leading `/' from member names

Let’s confirm the two files copied are available locally.

$ file dump_ops_in_flight.txt session_ls.txt
dump_ops_in_flight.txt: ASCII text
session_ls.txt:         ASCII text

Copy file to the Pod.

$ kubectl cp myfile.txt mypod1:/myfile.txt
$ kubectl exec -ti mypod1 -- ls
README.md  bin	boot  dev  dump_ops_in_flight.txt  etc	home  lib  lib64  lost+found  media  mnt  opt  proc  root  run	sbin  session_ls.txt  srv  sys	tmp  usr  var

For more examples check the help page.

26. DNS Debugging

Run DNS Utils Pod:

kubectl apply -f https://k8s.io/examples/admin/dns/dnsutils.yaml

Confirm pod is running:

kubectl get pods dnsutils

Running nslookup:

kubectl exec -i -t dnsutils -- nslookup <dns-entry>

Or gain shell access

kubectl exec -i -t dnsutils -- sh

Checking Local DNS configuration settings:

kubectl exec -ti dnsutils -- cat /etc/resolv.conf

Checking if DNS Pods are running:

$ kubectl get pods --namespace=kube-system -l k8s-app=kube-dns
NAME                       READY   STATUS    RESTARTS   AGE
coredns-5c59fd465f-777cw   1/1     Running   0          29m
coredns-5c59fd465f-bwpj4   1/1     Running   0          29m
coredns-5c59fd465f-sdndq   1/1     Running   0          29m
coredns-5c59fd465f-wldl9   1/1     Running   0          29m

Verify DNS endpoints are exposed:

kubectl get endpoints kube-dns --namespace=kube-system

27. Using Ingress Controller

Refer to dedicated articles in the following links:

28. Using Load Balancer

See below guides:

More to follow.

26
2.170.624,55

Cart