RSS Feed Subscribe to RSS Feed


Kubernetes HelloWorld

This tutorial covers how to deploy a simple HelloWorld app on Kubernetes, and expose it externally (as you might for a UI service, for example).

I found setting up the Kube cluster deployment very straightforward, but making it externally accessible much trickier, however it boils down to just two commands:

    $ kubectl create -f boothello-deployment.yaml

    $ kubectl expose -f boothello-service.yaml


See my previous post on how to do HelloWorld with Docker first. The following examples rely on the boothello docker image from that post, which I have uploaded to docker hub at


Create deployment

To create a deployment, I am using this yaml definition: boothello-deployment.yaml (this is based on this example:

Create the deployment as follows:

    $ kubectl create -f boothello-deployment.yaml
Alternative approaches

Feel free to skip this section, it is more of a side note, but it seems there are many ways to skin a cat in Kubernetes and that we could have used a number of other commands here to achieve a similar approach. e.g.

    $ kubectl run boothello-deployment --image=sabram/boothello

    $ kubectl create deployment boothello-deployment --image=sabram/boothello

I used the yaml file approach since I think it is a little more explicit and I wanted to be clear on exactly what I was doing! I think my (kubectl create -f) approach is the “Imperative object configuration”, described here

One way to see how the approaches subtly differ is to run each and then compare the out of

    $ kubectl describe deployments boothello-deployment
Check deployment status

Check on the rollout status:

    $ kubectl get deployments

And if the available pods still show as zero, check the rollout status with:

    $ kubectl rollout status deployment/boothello-deployment

If you see something like “Waiting for rollout to finish: 0 of X updated replicas are available…” with no other updates, try checking for issues with the individual pods by doing

    $ kubectl get pods


If all is working, then great! We have now deployed our app to a Kubernetes cluster.

Make deployment accessible

The cluster is not externally visible by default. There are a few ways to expose it, including using kubectl proxy, creating an Ingress, creating a LoadBalance Service or, as we will show here, creating a NodePort Service.

In this specific example (inspired by, we create a Service object of type NodePort that exposes the deployment, using this file boothello-service.yaml

    $ kubectl expose -f boothello-service.yaml

(to see another example of using NodePort, see


When complete, take a look at the service we just deployed:

    $ kubectl describe service boothello-service
    Name: boothello-service
    Namespace: default
    Labels: app=boothello
    Annotations: <none>
    Selector: app=boothello
    Type: NodePort
    LoadBalancer Ingress: localhost
    Port: <unset> 8080/TCP
    TargetPort: 8080/TCP
    NodePort: <unset> 31170/TCP
    Session Affinity: None
    External Traffic Policy: Cluster
    Events: <none>

You should now be able to access the app by using the Node Port:

curl localhost:31170


Other Options for exposing a cluster

For other ways to expose a cluster, see some notes here:

Having problems?

This may help (although I have never been able to get nslookup working on a pod! I guess I need to figure out how to have it included in the docker image?)

Also see


Tags: , , , ,

Leave a Reply