This tutorial walks you through how to deploy a simple hello-world application on a Tanzu Kubernetes (workload) cluster, expose it through an external IP address, and then access it online through a browser.

Prerequisites

If you plan to deploy the example application yourself, you need:

Deploy the Application on a Workload Cluster

Deploy the hello-world application by copying the example configuration YAML file and applying it to a workload cluster.

  1. Create a YAML file for the hello-world application with the following configuration:

    apiVersion: apps/v1
    kind: Deployment
    metadata:
     labels:
       app.kubernetes.io/name: load-balancer-example
     name: hello-world
    spec:
     replicas: 5
     selector:
       matchLabels:
         app.kubernetes.io/name: load-balancer-example
     template:
       metadata:
         labels:
           app.kubernetes.io/name: load-balancer-example
       spec:
         containers:
         - image: gcr.io/google-samples/node-hello:1.0
           name: hello-world
           ports:
           - containerPort: 8080
    
  2. Save the YAML file with the name load-balancer-example.yaml.

  3. Set kubectl to the context of the workload cluster by running:

    kubectl config use-context CLUSTER-admin@CLUSTER
    

    Where CLUSTER is the name of the workload cluster.

  4. Deploy the application on the workload cluster:

    kubectl apply -f load-balancer-example.yaml
    

    The output is similar to:

    deployment.apps/hello-world created
    

Expose the Application

Create a service object to expose the application's external IP address so you can access the application from a browser.

  1. Create a service object called my-service:

    kubectl expose deployment hello-world --type=LoadBalancer --name=my-service
    

    The output is similar to:

    service/my-service exposed
    

Access the Application Online

Access the hello-world application from a browser using its external IP address.

  1. Record the values for LoadBalancer Ingress and TargetPort from the output of the following command to use in the next step:

    kubectl describe services my-service
    

    The output is similar to:

    Name:                     my-service
    Namespace:                default
    Labels:                   app.kubernetes.io/name=load-balancer-example
    Annotations:              <none>
    Selector:                 app.kubernetes.io/name=load-balancer-example
    Type:                     LoadBalancer
    IP Families:              <none>
    IP:                       100.67.254.91
    IPs:                      100.67.254.91
    LoadBalancer Ingress:     10.186.21.200
    Port:                     <unset>  8080/TCP
    TargetPort:               8080/TCP
    NodePort:                 <unset>  32202/TCP
    Endpoints:                100.96.1.15:8080,100.96.1.16:8080,100.96.1.17:8080 + 2 more...
    Session Affinity:         None
    External Traffic Policy:  Cluster
    

    Note: If you do not see LoadBalancer Ingress, ensure you have a load balancer configured for this workload cluster.

  2. In a browser, navigate to https://IP:PORT where IP is the value of LoadBalancer Ingress and PORT is the port number value of TargetPort that you recorded in the previous step. For example, https://10.186.21.200:8080.

    The hello-world application displays the following:

    Hello Kubernetes!
    

What to Do Next

Now your application is deployed, you can manage traffic, view logs, and monitor its operations with packages, such as Contour, Fluent Bit, Prometheus, and Grafana. To install these packages, see Install and Configure Packages.

check-circle-line exclamation-circle-line close-line
Scroll to top icon