Deploying a Container on VMware vSphere Kubernetes Service (VKS)

If you’re running VMware vSphere Kubernetes Service (VKS) and want to deploy a containerized application, the process is very similar to deploying workloads on any standard Kubernetes cluster.

At a high level, the workflow looks like this:

Container image → VKS cluster → kubectl → Deployment → Service → Load Balancer or Ingress

This guide walks through the basic process, from connecting to a VKS workload cluster to exposing your application.

Prerequisites

Before you begin, you’ll need:

  • A running VKS workload cluster
  • Access to the vSphere/VCF environment
  • kubectl installed
  • Credentials that allow you to access the workload cluster
  • A container image available from a registry, such as Harbor, Docker Hub, or another OCI-compatible registry

For the examples below, we’ll assume the application listens on port 8080 and the image is:

myregistry.example.com/myapp:1.0

1. Connect to the VKS cluster

Once your VKS workload cluster has been created, the first step is to configure kubectl to communicate with it.

Depending on your VKS environment and version, you can use the VMware tooling to obtain a Kubernetes context. For example:

kubectl vsphere login \
  --server=<SUPERVISOR_VIP> \
  --tanzu-kubernetes-cluster-namespace=<VSPHERE_NAMESPACE> \
  --tanzu-kubernetes-cluster-name=<VKS_CLUSTER_NAME> \
  -u <USERNAME>

After authenticating, verify that you can reach the cluster:

kubectl get nodes

You should see the worker nodes associated with your VKS cluster and their status should be Ready.

2. Create a Kubernetes Deployment

With access to the cluster, the next step is to tell Kubernetes which container you want to run.

Create a file called myapp.yaml:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp
spec:
  replicas: 2
  selector:
    matchLabels:
      app: myapp
  template:
    metadata:
      labels:
        app: myapp
    spec:
      containers:
        - name: myapp
          image: myregistry.example.com/myapp:1.0
          ports:
            - containerPort: 8080

Apply the configuration:

kubectl apply -f myapp.yaml

Then check the deployment and Pods:

kubectl get deployments
kubectl get pods

The Deployment tells Kubernetes how many instances of your application should be running. In this example, Kubernetes will maintain two Pods.

If a Pod fails, Kubernetes can create a replacement automatically.

3. Create a Service

A Deployment manages the application, but it doesn’t by itself provide a stable network endpoint.

For that, create a Kubernetes Service.

Create myapp-service.yaml:

apiVersion: v1
kind: Service
metadata:
  name: myapp
spec:
  selector:
    app: myapp
  ports:
    - port: 80
      targetPort: 8080
  type: ClusterIP

Apply it:

kubectl apply -f myapp-service.yaml

You can inspect the resulting Service with:

kubectl get service myapp

The ClusterIP Service provides a stable internal endpoint that other workloads in the Kubernetes cluster can use to communicate with your application.

Notice that the Service listens on port 80 but forwards traffic to port 8080 on the application Pods.

4. Expose the application externally

If users outside the Kubernetes cluster need to access the application, you’ll need an externally accessible endpoint.

One option is to use a LoadBalancer Service:

apiVersion: v1
kind: Service
metadata:
  name: myapp
spec:
  selector:
    app: myapp
  ports:
    - port: 80
      targetPort: 8080
  type: LoadBalancer

Apply the updated configuration:

kubectl apply -f myapp-service.yaml

Then check the Service:

kubectl get svc myapp

If your VKS environment has a compatible load-balancer integration configured, Kubernetes should provision an external address for the Service.

The exact behavior depends on how networking and load balancing have been configured in your VMware Cloud Foundation environment.

For larger environments, you may instead use an Ingress controller to expose multiple applications through a shared entry point and hostname-based routing.

5. Troubleshoot the deployment

If the application doesn’t start as expected, Kubernetes provides several useful commands for troubleshooting.

Start by checking the Pods:

kubectl get pods

For more information about a particular Pod:

kubectl describe pod <pod-name>

To inspect the application’s logs:

kubectl logs <pod-name>

You can also watch Pods as Kubernetes creates or replaces them:

kubectl get pods -w

If a Pod is stuck in states such as Pending, ImagePullBackOff, or CrashLoopBackOff, kubectl describe and kubectl logs are usually good places to start.

A quick example

For a simple test, you can deploy nginx without creating YAML files manually:

kubectl create deployment nginx --image=nginx:latest
kubectl expose deployment nginx --port=80 --type=LoadBalancer

Then check the status:

kubectl get pods
kubectl get svc nginx

This is useful for quickly validating that your VKS cluster can schedule Pods and expose a Service.

Putting it all together

Deploying a container to VKS isn’t fundamentally different from deploying an application to Kubernetes elsewhere. VKS provides the Kubernetes cluster infrastructure; Kubernetes resources such as Deployments and Services define how your application runs.

The basic workflow is:

  1. Connect to the VKS workload cluster
  2. Create a Deployment that references your container image
  3. Create a Service to provide stable network access
  4. Use a LoadBalancer or Ingress if the application needs to be accessible externally
  5. Use kubectl to monitor and troubleshoot the workload

Once you understand this workflow, you can build on it with Kubernetes features such as ConfigMaps, Secrets, persistent storage, resource requests and limits, health probes, autoscaling, Ingress, and rolling deployments.

Leave a Reply

Your email address will not be published. Required fields are marked *

Share on Social Media