This tutorial walks you through how to deploy a simple hello-world
application on a Tanzu Kubernetes Grid (TKG) workload cluster, expose it through an external IP address, and then access it online through a browser.
To deploy the example application, you need:
kubectl
, and the Carvel tools. For instructions, see Install the Tanzu CLI and Other Tools for Use with a vSphere with Tanzu Supervisor or Install the Tanzu CLI and Other Tools for Use with Standalone Management Clusters.Deploy the hello-world
application by copying the example configuration YAML file and applying it to a workload cluster.
NoteVMware recommends never deploying workloads to a standalone management cluster itself because:
- Standalone management clusters and workload clusters have separate concerns.
- Standalone management clusters are not backed up like workload clusters. To ensure resilience, standalone management cluster configuration is best managed as code.
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
NoteIf 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 Installing and Managing Packages with the Tanzu CLI.
To back up and restore or migrate your workloads with Velero, see Back Up and Restore Cluster Workloads.