Cart

    Sorry, we could not find any results for your search querry.

    Deploying a hello node in Kubernetes

    In our Kubernetes quickstart tutorial, we showed how to prepare your Kubernetes cluster for use. At the end, you can check the status of your cluster, but... what's next?

    In Kubernetes, you almost always start by creating a Deployment based on a container image. As part of this, one or more Pods (a group of one or more containers) are created.

    In this tutorial , we show how to create a Kubernetes Deployment by deploying a 'hello node' container image as an example. In this example, one Pod is created, but in a practical use case, there are usually more Pods.

    For the steps in this tutorial, it is important to have Kubectl installed and to have downloaded your Kubeconfig file.


    Creating a Kubernetes Hello Node Deployment

     

    Step 1

    Create a Deployment with the following command. We use the hello-node container image from the official Kubernetes organization for this.

    kubectl create deployment hello-node --image=registry.k8s.io/echoserver:1.4

    You will see the following confirmation:

    deployment.apps/hello-node created

    So far so good. We will immediately go through some useful management commands that allow you to check the status of different aspects of your Deployment.

     

    Checking the status of your Deployment

    Check the status of your new Deployment immediately with the command:

    kubectl get deployments

    If you host multiple Deployments, you will see them all with this command. If this is your only Deployment, the output looks like this:

    NAME READY UP-TO-DATE AVAILABLE AGE 
    hello-node 1/1 1 1 54s

     

    Checking the status of your Pods

    Next, check the status of your Pods:

    kubectl get pods

    The output looks like this. No matter how many Pods you have or which Deployments they belong to, you will see them all here. You can recognize your Deployment by the fact that the name of your Pod always starts with the name of your Deployment.

    NAME READY STATUS RESTARTS AGE 
    hello-node-74bfcb5b58-zkxdt 1/1 Running 0 1m2s

    There are many more commands available. An overview of some of the most useful for managing your cluster can be found in this tutorial.


     

    Step 2

    By default, the Pod is only accessible from the internal virtual network of your Kubernetes cluster and not via the public internet. To make your hello-node container accessible to the public internet, you 'expose' the Pod as a Kubernetes Service of type 'LoadBalancer'.

    kubectl expose deployment hello-node --type=LoadBalancer --port=8080
     
    The addition --type=LoadBalancer indicates that you want to create a LoadBalancer Service and expose your Pods to the public internet. For this, an HA-IP load balancer is automatically created for your Deployment in our systems. The application in the 'hello node' container image only listens for traffic on port 8080. In your own use case, this could be another port.

    You will see a clear confirmation:

    service/hello-node exposed

    You can see the status of your LoadBalancer Service (and all other Kubernetes Services on your cluster) with the command:

    kubectl get services

    For a new cluster, the output looks something like this:

    NAME         TYPE           CLUSTER-IP       EXTERNAL-IP                       PORT(S)          AGE
    hello-node   LoadBalancer   10.105.123.234   86-123-234-123.haip.transip.net   8080:30625/TCP   1m1s
    kubernetes   ClusterIP      10.96.0.1                                          443/TCP          11d

     

    Step 3

    Finally, there is one more thing to do: testing your hello node Deployment.

    Open a browser and go to the IP address you see at the end of step 2 under 'EXTERNAL-IP' with the addition of :8080 for the port on which the service listens, for example 86-123-234-123.haip.transip.net:8080

    The external IP is in fact a subdomain. The actual IP address is the number sequence but with . instead of - for example 86.123.234.123. At any time you can also review the load balancer IP addresses in the control panel by navigating to the 'Load Balancers' tab of your cluster.

    Unlike what you might expect you're not shown a 'hello world' message, but some client information:

    CLIENT VALUES:
    client_address=10.128.0.3
    command=GET
    real path=/
    query=nil
    request_version=1.1
    request_uri=http://86-123-234-123.haip.transip.net:8080/
    
    SERVER VALUES:
    server_version=nginx: 1.10.0 - lua: 10001
    
    HEADERS RECEIVED:
    accept=text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
    accept-encoding=gzip, deflate
    accept-language=en-US,en;q=0.5
    connection=keep-alive
    host=86-105-246-14.haip.transip.net:8080
    upgrade-insecure-requests=1
    user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:105.0) Gecko/20100101 Firefox/105.0
    BODY:
    -no body in request-

    Removing the Deployment and associated services

     

    Now that you have finished testing a hello node Deployment, you may want to remove it. This consists of two parts: deleting the created services and deleting the actual Deployment.

    kubectl delete service hello-node
    kubectl delete deployment hello-node

    If you are not sure anymore about the name of your Service(s) or Deployment, you can retrieve them again with the following commands respectively:

    kubectl get services
    kubectl get deployments

    This brings us to the end of this tutorial on deploying a hello node in Kubernetes.

    Need help?

    Receive personal support from our supporters

    Contact us