3.2.3 Deploying to Kubernetes

View in the book. Buy the book.

Lets deploy the container to Kubernetes!

Deploy

cd Chapter03/3.2_DeployingToKubernetes/
kubectl create -f deploy.yaml

Query the status

$ kubectl get deploy
NAME         READY   UP-TO-DATE   AVAILABLE   AGE
timeserver   0/3     3            0           7s

It may take 1-2 minutes to become ready.

$ kubectl get pods
NAME                         READY   STATUS    RESTARTS   AGE
timeserver-f94cc5dd9-jntt4   0/1     Pending   0          39s
timeserver-f94cc5dd9-swl4h   0/1     Pending   0          39s
timeserver-f94cc5dd9-xwbnx   0/1     Pending   0          39s

Now it’s ready

$ kubectl get pods
NAME                         READY   STATUS    RESTARTS   AGE
timeserver-f94cc5dd9-jntt4   1/1     Running   0          3m53s
timeserver-f94cc5dd9-swl4h   1/1     Running   0          3m53s
timeserver-f94cc5dd9-xwbnx   1/1     Running   0          3m53s

You can also view just the Pods in this deployment by referencing the label

$ kubectl get pods --selector=pod=timeserver-pod
NAME                         READY   STATUS    RESTARTS   AGE
timeserver-f94cc5dd9-jntt4   1/1     Running   0          4m7s
timeserver-f94cc5dd9-swl4h   1/1     Running   0          4m7s
timeserver-f94cc5dd9-xwbnx   1/1     Running   0          4m7s

To hit the service, forward the port

$ kubectl port-forward deploy/timeserver 8080:80
Forwarding from 127.0.0.1:8080 -> 80
Forwarding from [::1]:8080 -> 80

View with curl or Cloud Shell’s web preview like sectiion 2.2.1

To view and follow the logs for a container in the deployment:

$ kubectl logs -f deploy/timeserver
Found 3 pods, using pod/timeserver-8bbb895dc-kgl8l
Listening on 0.0.0.0:80
127.0.0.1 - - [09:59:08] “GET / HTTP/1.1” 200 –

You can also follow the logs of a specific container.

Or to print all logs for the pods:

$ kubectl logs --selector=pod=timeserver-pod
Listening on 0.0.0.0:80
127.0.0.1 - - [12/Nov/2023 18:47:04] "GET /?authuser=0&redirectedPreviously=true HTTP/1.1" 200 -
127.0.0.1 - - [12/Nov/2023 18:47:05] "GET /favicon.ico HTTP/1.1" 200 -
127.0.0.1 - - [12/Nov/2023 18:50:04] "GET /?authuser=0&redirectedPreviously=true HTTP/1.1" 200 -
127.0.0.1 - - [12/Nov/2023 18:50:05] "GET /?authuser=0&redirectedPreviously=true HTTP/1.1" 200 -
127.0.0.1 - - [12/Nov/2023 18:50:07] "GET /?authuser=0&redirectedPreviously=true HTTP/1.1" 200 -
127.0.0.1 - - [12/Nov/2023 18:50:08] "GET /favicon.ico HTTP/1.1" 200 -
Listening on 0.0.0.0:80
Listening on 0.0.0.0:80