Skip to content

Deploy a local Kubernetes Cluster

If you do not have access to a managed Kubernetes cluster you can deploy one on your local machine or VM. This document describes deploying a cluster with kind. Refer to the documentation for additional information.

Demo Use Only

The instructions in this document are for testing and learning, and not intended for use in production.

Why not Docker Desktop?

The process outlined on this page will create a Kubernetes in Docker (kind) cluster. Kind is very similar in functionality to the Docker Desktop implementation of Kubernetes, but the advantage here is that it is more portable (not requiring Docker Desktop). In addition, the files provided will enable and deploy an ingress controller for communicating with the services in the cluster. In the Getting Started example, port-forwarding was needed with Docker Desktop. With the ingress in place, a port-forward is not required.

Prerequisites

Docker System Resources

Docker on Linux is typically installed with root privileges and thus has access to the full resources of the machine. Docker Desktop for Mac and Windows provides a way to set the resources allocated to Docker. For this documentation, a Macbook Pro was configured to use 3 CPUs and 6 GB Memory. You can adjust these values as necessary for your needs.

Kubernetes Version

For this guide, the kind implementation of Kubernetes 1.24 is used.

Steps

  1. Install kind on your platform.

  2. Use the provided sample kind.yaml file to create a kind cluster named ping with ingress enabled. From the root of the repository code, run:

    kind create cluster --config=./20-kubernetes/kind.yaml
    

    Output:

  3. Test cluster health by running the following commands:

    kubectl cluster-info
    
    # Output - port will vary
    Kubernetes control plane is running at https://127.0.0.1:63564
    CoreDNS is running at https://127.0.0.1:63564/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
    
    To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
    
    ------------------
    
    kubectl version --short
    
    < output removed >
    Server Version: v1.24.0
    
    ------------------
    
    kubectl get nodes
    
    NAME                 STATUS   ROLES           AGE     VERSION
    ping-control-plane   Ready    control-plane   4m26s   v1.24.0
    
  4. Next, install the nginx-ingress-controller for kind. In the event the Github file is unavailable, a copy has been made to this repository here.

To use the Github file:

kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.3.0/deploy/static/provider/kind/1.24/deploy.yaml

To use the local copy:

kubectl apply -f ./20-kubernetes/kind-nginx.yaml

  1. To wait for the Nginx ingress to reach a healthy state, run the following command. You can also observe the pod status using k9s or by running kubectl get pods --namespace ingress-nginx. You should see one controller pod running when the ingress controller is ready. This command should exit after no more than 90 seconds or so, depending on the speed of your computer:

    kubectl wait --namespace ingress-nginx \
      --for=condition=ready pod \
      --selector=app.kubernetes.io/component=controller \
      --timeout=90s
    
  2. Verify nginx-ingress-controller is working:

    curl localhost
    

    Output:

    <html>
    <head><title>404 Not Found</title></head>
    <body>
    <center><h1>404 Not Found</h1></center>
    <hr><center>nginx</center>
    </body>
    </html>
    

Our examples will use the Helm release name myping and DNS domain suffix *ping-local.com for accessing applications. You can add all expected hosts to /etc/hosts:

echo '127.0.0.1 myping-pingaccess-admin.ping-local.com myping-pingaccess-engine.ping-local.com myping-pingauthorize.ping-local.com myping-pingauthorizepap.ping-local.com myping-pingdataconsole.ping-local.com myping-pingdelegator.ping-local.com myping-pingdirectory.ping-local.com myping-pingdatagovernance.ping-local.com myping-pingdatagovernancepap.ping-local.com myping-pingfederate-admin.ping-local.com myping-pingfederate-engine.ping-local.com myping-pingcentral.ping-local.com' | sudo tee -a /etc/hosts > /dev/null

Setup is complete. This local Kubernetes environment should be ready to deploy our Helm examples

Stop the cluster

When you are finished, you can remove the cluster by running the following command. Doing so will require you to create the cluster and install the ingress controller when you want another cluster.

kind delete cluster --name ping