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.
If you plan to deploy the example application yourself, you need:
kubectl
. To install kubectl
, see Download and Unpack the Tanzu CLI and kubectl
in Install the Tanzu CLI and Other Tools.Deploy the hello-world
application by copying the example configuration YAML file and applying it to a workload cluster.
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
If your workload cluster uses a Windows image as detailed in Windows Custom Machine Images, add the following spec.template.spec.tolerations
and indent it inline with containers
above:
tolerations:
- value: "windows"
key: os
operator: Equal
effect: "NoSchedule"
nodeSelector:
kubernetes.io/os: windows
Save the YAML file with the name load-balancer-example.yaml
.
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.
Deploy the application on the workload cluster:
kubectl apply -f load-balancer-example.yaml
The output is similar to:
deployment.apps/hello-world created
Create a service object to expose the application’s external IP address so you can access the application from a browser.
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 hello-world
application from a browser using its external IP address.
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.
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!
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.