Pivotal Container Service v1.2

Deploying and Exposing Basic Workloads

Page last updated:

This topic describes how to configure, deploy, and expose basic workloads in Pivotal Container Service (PKS).

Overview

A load balancer is a third-party device that distributes network and application traffic across resources. Using a load balancer can prevent individual network components from being overloaded by high traffic.

Note: The procedures in this topic create a dedicated load balancer for each workload. If your cluster has many apps, a load balancer dedicated to each workload can be an inefficient use of resources. An ingress controller pattern is better suited for clusters with many workloads.

Refer to the following PKS documentation topics for additional information about deploying and exposing workloads:

Prerequisites

This topic references standard Kubernetes primitives. If you are unfamiliar with Kubernetes primitives, review the Kubernetes Workloads and Services, Load Balancing, and Networking documentation before following the procedures below.

vSphere without NSX-T Prerequisites

If you use vSphere without NSX-T, you can choose to configure your own external load balancer or expose static ports to access your workload without a load balancer. See Deploy Workloads without a Load Balancer below.

GCP, AWS, Azure, and vSphere with NSX-T Prerequisites

If you use Google Cloud Platform (GCP), Amazon Web Services (AWS), Azure, or vSphere with NSX-T integration, your cloud provider can configure a public-cloud external load balancer for your workload. See either Deploy Workloads on vSphere with NSX-T or Deploy Workloads on GCP, AWS, or Azure, Using a Public-Cloud External Load Balancer below.

AWS Prerequisites

If you use AWS, you can also expose your workload using a public-cloud internal load balancer.

Perform the following steps before you create a load balancer:

  1. In the AWS Management Console, create or locate a public subnet for each availability zone (AZ) that you are deploying to. A public subnet has a route table that directs internet-bound traffic to the internet gateway.

  2. On the command line, run pks cluster CLUSTER-NAME, where CLUSTER-NAME is the name of your cluster.

  3. Record the unique identifier for the cluster.

  4. In the AWS Management Console, tag each public subnet based on the table below, replacing CLUSTER-UUID with the unique identifier of the cluster. Leave the Value field empty.

    Key Value
    kubernetes.io/cluster/service-instance_CLUSTER-UUID empty

    Note: AWS limits the number of tags on a subnet to 100.

After completing these steps, follow the steps below in Deploy AWS Workloads Using an Internal Load Balancer.

Deploy Workloads on vSphere with NSX-T

If you use vSphere with NSX-T, follow the steps below to deploy and expose basic workloads using the NSX-T load balancer.

Configure Your Workload

  1. Open your workload’s Kubernetes service configuration file in a text editor.

  2. To expose the workload through a load balancer, confirm that the Service object is configured to be type: LoadBalancer.

    For example:

    ---
    apiVersion: v1
    kind: Service
    metadata:
      labels:
        name: nginx
      name: nginx
    spec:
      ports:
        - port: 80
      selector:
        app: nginx
      type: LoadBalancer
    ---
    
  3. Confirm the workload’s Kubernetes service configuration is set to be type: LoadBalancer.

  4. Confirm the type property of each workload’s Kubernetes service is similarly configured.

Note: For an example of a fully configured Kubernetes service, see the nginx app’s example type: LoadBalancer configuration in GitHub.

For more information about configuring the LoadBalancer Service type see the Kubernetes documentation.

Deploy and Expose Your Workload

  1. To deploy the service configuration for your workload, run the following command:

    kubectl apply -f SERVICE-CONFIG
    

    Where SERVICE-CONFIG is your workload’s Kubernetes service configuration.

    For example:

    kubectl apply -f nginx.yml
    This command creates three pod replicas, spanning three worker nodes.

  2. Deploy your applications, deployments, config maps, persistent volumes, secrets, and any other configurations or objects necessary for your applications to run.

  3. Wait until your cloud provider has created and connected a dedicated load balancer to the worker nodes on a specific port.

Access Your Workload

  1. To determine your exposed workload’s load balancer IP address and port number, run the following command:

    kubectl get svc SERVICE-NAME
    

    Where SERVICE-NAME is your workload configuration’s specified service name.

    For example:

    kubectl get svc nginx

  2. Retrieve the load balancer’s external IP address and port from the returned listing.

  3. To access the app, run the following on the command:

    curl http://EXTERNAL-IP:PORT
    

    Where:

    • EXTERNAL-IP is the IP address of the load balancer
    • PORT is the port number.

    Note: This command should be run on a server with network connectivity and visibility to the IP address of the worker node.

Deploy Workloads on GCP, AWS, or Azure, Using a Public-Cloud External Load Balancer

If you use GCP, AWS, or Azure, follow the steps below to deploy and expose basic workloads using a load balancer configured by your cloud provider.

Configure Your Workload

  1. Open your workload’s Kubernetes service configuration file in a text editor.

  2. To expose the workload through a load balancer, confirm that the Service object is configured to be type: LoadBalancer.

    For example:

    ---
    apiVersion: v1
    kind: Service
    metadata:
      labels:
        name: nginx
      name: nginx
    spec:
      ports:
        - port: 80
      selector:
        app: nginx
      type: LoadBalancer
    ---
    
  3. Confirm the workload’s Kubernetes service configuration is set to be type: LoadBalancer.

  4. Confirm the type property of each workload’s Kubernetes service is similarly configured.

Note: For an example of a fully configured Kubernetes service, see the nginx app’s example type: LoadBalancer configuration in GitHub.

For more information about configuring the LoadBalancer Service type see the Kubernetes documentation.

Deploy and Expose Your Workload

  1. To deploy the service configuration for your workload, run the following command:

    kubectl apply -f SERVICE-CONFIG
    

    Where SERVICE-CONFIG is your workload’s Kubernetes service configuration.

    For example:

    kubectl apply -f nginx.yml
    This command creates three pod replicas, spanning three worker nodes.

  2. Deploy your applications, deployments, config maps, persistent volumes, secrets, and any other configurations or objects necessary for your applications to run.

  3. Wait until your cloud provider has created and connected a dedicated load balancer to the worker nodes on a specific port.

Access Your Workload

  1. To determine your exposed workload’s load balancer IP address and port number, run the following command:

    kubectl get svc SERVICE-NAME
    

    Where SERVICE-NAME is your workload configuration’s specified service name.

    For example:

    kubectl get svc nginx

  2. Retrieve the load balancer’s external IP address and port from the returned listing.

  3. To access the app, run the following on the command:

    curl http://EXTERNAL-IP:PORT
    

    Where:

    • EXTERNAL-IP is the IP address of the load balancer
    • PORT is the port number.

    Note: This command should be run on a server with network connectivity and visibility to the IP address of the worker node.

Deploy AWS Workloads Using an Internal Load Balancer

If you use AWS, follow the steps below to deploy, expose, and access basic workloads using an internal load balancer configured by your cloud provider.

Configure Your Workload

  1. Open your workload’s Kubernetes service configuration file in a text editor.

  2. To expose the workload through a load balancer, confirm that the Service object is configured to be type: LoadBalancer.

  3. In the services metadata section of the manifest, add the following annotations tag:

    annotations:
          service.beta.kubernetes.io/aws-load-balancer-internal: 0.0.0.0/0
    

    For example:

    ---
    apiVersion: v1
    kind: Service
    metadata:
      labels:
        name: nginx
      annotations:
            service.beta.kubernetes.io/aws-load-balancer-internal: 0.0.0.0/0
      name: nginx
    spec:
      ports:
        - port: 80
      selector:
        app: nginx
      type: LoadBalancer
      ---
    
  4. Confirm that the workload’s Kubernetes service configuration is set to be type: LoadBalancer.

  5. Confirm that the annotations and type properties of each workload’s Kubernetes service are similarly configured.

Note: For an example of a fully configured Kubernetes service, see the nginx app’s example type: LoadBalancer configuration in GitHub.

For more information about configuring the LoadBalancer Service type see the Kubernetes documentation.

Deploy and Expose Your Workload

  1. To deploy the service configuration for your workload, run the following command:

    kubectl apply -f SERVICE-CONFIG
    

    Where SERVICE-CONFIG is your workload’s Kubernetes service configuration.
    For example:

    kubectl apply -f nginx.yml
    This command creates three pod replicas, spanning three worker nodes.

  2. Deploy your applications, deployments, config maps, persistent volumes, secrets, and any other configurations or objects necessary for your applications to run.

  3. Wait until your cloud provider has created and connected a dedicated load balancer to the worker nodes on a specific port.

Access Your Workload

  1. To determine your exposed workload’s load balancer IP address and port number, run the following command:

    kubectl get svc SERVICE-NAME
    

    Where SERVICE-NAME is your workload configuration’s specified service name.
    For example:

    kubectl get svc nginx

  2. Retrieve the load balancer’s external IP and port from the returned listing.

  3. To access the app, run the following command:

    curl http://EXTERNAL-IP:PORT
    

    Where:

    • EXTERNAL-IP is the IP address of the load balancer.
    • PORT is the port number.

    Note: This command should be run on a server with network connectivity and visibility to the IP address of the worker node.

Deploy Workloads for a Generic External Load Balancer

Follow the steps below to deploy and access basic workloads using a generic external load balancer, such as F5.

In this approach you will access you workloads with a generic external load balancer.

Using a generic external load balancer requires a static port in your Kubernetes cluster. To do this we need to expose your workloads with a NodePort.

Configure Your Workload

To expose a static port on your workload, perform the following steps:

  1. Open your workload’s Kubernetes service configuration file in a text editor.

  2. To expose the workload without a load balancer, confirm that the Service object is configured to be type: NodePort.
    For example:

    ---
    apiVersion: v1
    kind: Service
    metadata:
      labels:
        name: nginx
      name: nginx
    spec:
      ports:
        - port: 80
      selector:
        app: nginx
      type: NodePort
    ---
    
  3. Confirm that the workload’s Kubernetes service configuration is set to be type: NodePort.

  4. Confirm that the type property of each workload’s Kubernetes service is similarly configured.

Note: For an example of a fully configured Kubernetes service, see the nginx app’s example type: NodePort configuration in GitHub.

For more information about configuring the NodePort Service type see the Kubernetes documentation.

Deploy and Expose Your Workload

  1. To deploy the service configuration for your workload, run the following command:

    kubectl apply -f SERVICE-CONFIG
    

    Where SERVICE-CONFIG is your workload’s Kubernetes service configuration.
    For example:

    kubectl apply -f nginx.yml
    This command creates three pod replicas, spanning three worker nodes.

  2. Deploy your applications, deployments, config maps, persistent volumes, secrets, and any other configurations or objects necessary for your applications to run.

  3. Wait until your cloud provider has connected your worker nodes on a specific port.

Access Your Workload

  1. Retrieve the IP address for a worker node with a running app pod.

    Note: If you deployed more than four worker nodes, some worker nodes may not contain a running app pod. Select a worker node that contains a running app pod.

    You can retrieve the IP address for a worker node with a running app pod in one of the following ways:

    • On the command line, run the following
    kubectl get nodes -L spec.ip
    
    • On the Ops Manager command line, run the following to find the IP address:
    bosh vms
    

    This IP address will be used when configuring your external load balancer.

  2. To see a listing of port numbers, run the following command:

    kubectl get svc SERVICE-NAME
    

    Where SERVICE-NAME is your workload configuration’s specified service name.
    For example:

    kubectl get svc nginx

  3. Find the node port number in the 3XXXX range. This port number will be used when configuring your external load balancer.

  4. Configure your external load balancer to map your application Uri to the IP and port number you collected above. Please refer to your load balancer documentation for instructions.

Deploy Workloads without a Load Balancer

If you do not use an external load balancer, you can configure your service to expose a static port on each worker node. The following steps configure your service to be reachable from outside the cluster at http://NODE-IP:NODE-PORT.

Configure Your Workload

To expose a static port on your workload, perform the following steps:

  1. Open your workload’s Kubernetes service configuration file in a text editor.

  2. To expose the workload without a load balancer, confirm that the Service object is configured to be type: NodePort.
    For example:

    ---
    apiVersion: v1
    kind: Service
    metadata:
      labels:
        name: nginx
      name: nginx
    spec:
      ports:
        - port: 80
      selector:
        app: nginx
      type: NodePort
    ---
    
  3. Confirm that the workload’s Kubernetes service configuration is set to be type: NodePort.

  4. Confirm that the type property of each workload’s Kubernetes service is similarly configured.

Note: For an example of a fully configured Kubernetes service, see the nginx app’s example type: NodePort configuration in GitHub.

For more information about configuring the NodePort Service type see the Kubernetes documentation.

Deploy and Expose Your Workload

  1. To deploy the service configuration for your workload, run the following command:

    kubectl apply -f SERVICE-CONFIG
    

    Where SERVICE-CONFIG is your workload’s Kubernetes service configuration.
    For example:

    kubectl apply -f nginx.yml
    This command creates three pod replicas, spanning three worker nodes.

  2. Deploy your applications, deployments, config maps, persistent volumes, secrets, and any other configurations or objects necessary for your applications to run.

  3. Wait until your cloud provider has connected your worker nodes on a specific port.

Access Your Workload

  1. Retrieve the IP address for a worker node with a running app pod.

    Note: If you deployed more than four worker nodes, some worker nodes may not contain a running app pod. Select a worker node that contains a running app pod.

    You can retrieve the IP address for a worker node with a running app pod in one of the following ways:

    • On the command line, run the following
    kubectl get nodes -L spec.ip
    
    • On the Ops Manager command line, run the following to find the IP address:
    bosh vms
    
  2. To see a listing of port numbers, run the following command:

    kubectl get svc SERVICE-NAME
    

    Where SERVICE-NAME is your workload configuration’s specified service name.
    For example:

    kubectl get svc nginx

  3. Find the node port number in the 3XXXX range.

  4. To access the app, run the following command line:

    curl http://NODE-IP:NODE-PORT
    

    Where

    • NODE-IP is the IP address of the worker node.
    • NODE-PORT is the node port number.

    Note: Run this command on a server with network connectivity and visibility to the IP address of the worker node.


Please send any feedback you have to pks-feedback@pivotal.io.

Create a pull request or raise an issue on the source for this page in GitHub