kubectl: create pod

Let’s try creating a pod.

  1. create a pod.ymlwith your favourite image:

 

Then:

kubectl create -f pod.yml

returns

pod/hello-pod created

but we need to check what’s going on behind the scenes with:

kubectl get pods

Or if you have loads of pods, you can use:

kubectl get pods/hello-pod

or all pods in all namespaces:

kubectl get pods --all-namespaces

“kubectl get pods” warnings

kubectl get pods
NAME READY STATUS RESTARTS AGE
hello-pod 0/1 ContainerCreating 0 1m

kubectl describe pods

This:

Reason: ContainerCreating

is because it’s still creating the container.

kubectl get pods
NAME READY STATUS RESTARTS AGE
hello-pod 0/1 ImagePullBackOff 0 10m

Again:

kubectl describe pods

Reason: ImagePullBackOff

means there’s a problem with the image.

Check with:

docker inspect --type=image <name of image>:latest

I was getting:

Error: No such image:

So, let’s try another image. i.e. in pod.ymllet’s use:

image: hello-world:latest

Now create hits:

 

Let’s try deleting this pod with:

https://kubernetes.io/docs/tasks/run-application/force-delete-stateful-set-pod/

 

Let’s try --all as mentioned:

Solution is:

Note: this can take a few minutes.

https://kubernetes.io/docs/tasks/run-application/force-delete-stateful-set-pod/

 

Let’s try create again:

What is a CrashLoopBackOff? How to alert, debug / troubleshoot, and fix Kubernetes CrashLoopBackOff events.

Why am I getting this?

‘cos the hello-world image exits after printing out its introductory message.

Let’s try:

image: yeasy/simple-web:latest

We can keep track of events with:

kubectl get events

After around 5 mins it comes up. Let’s interact with the web server. First what IP does it have?

kubectl get pods -l zone=prod -o yaml | grep IP

kubectl get pods
NAME READY STATUS RESTARTS AGE
hello-pod 1/1 Running 0 12m

kubectl exec -it hello-pod — /bin/bash

and

curl -i localhost:80

shows it’s working.

 

Note: you’d normally deploy a pod using a ReplicationController.

Delete existing pod with:

kubectl delete pods hello-pod

and create a ReplicationController with:

Note: 4 top-level objects are:

  • apiVersion
  • kind
  • metadata
  • spec

then

kubectl create -f rc.yml

And inspect with:

To increase replicas, update rc.yml and apply with:

kubectl apply -f rc.yml

 

Other errors

Unable to connect to the server

Unable to connect to the server: dial tcp 192.168.64.5:8443: i/o timeout

  • check minikube is started – minikube start

kubectl describe pods

 

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *