Connect to KinD

KinD clusters run Kubernetes via Docker containers. As long as you have access to a Docker daemon, you can run KinD!

Check out the docs to install and interact with the kind CLI, if you haven’t already.

By default, KinD sets up the Kubernetes API server IP to be the local loopback address (127.0.0.1). This is fine for interacting with the cluster from the context of your host, but when it comes to talking to the cluster from inside of another Docker image, as is the case when running an action on a Porter bundle using the default Docker driver, further configuration is needed to make this communication possible.

There are two main options:

  1. Set up public DNS to map to the default API server address. This would ideally include ingress TLS and so presents a secure option for communication, but does involve a larger overhead for setup.
  2. Configure the KinD cluster to use an IP address that is already resolvable from within Porter’s Docker container. This will most likely lead to considerable security implications and is not advised for clusters hosting actual workloads or sensitive information.

Here we’ll look at the latter option of configuring the KinD cluster to use a different API Server address.

KinD Setup

First, we need to determine our host IP address. I’ll take the example of a Mac OSX host:

$ ifconfig en0 | awk '/inet / {print $2; }' | cut -d ' ' -f 2
10.0.1.4

We can then use this IP in the KinD config:

kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
networking:
  apiServerAddress: 10.0.1.4
  apiServerPort: 6443

After saving the config to kind-config.yaml, we can create our cluster:

$ kind create cluster --config kind-config.yaml

Once the cluster is successfully created, the generated kubeconfig should be merged into the default location (~/.kube/config or the location specified by the KUBECONFIG env var). We can test API server communications with kubectl:

 $ kubectl cluster-info
Kubernetes master is running at https://10.0.1.4:6443
KubeDNS is running at https://10.0.1.4:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy

To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.

Porter time!

Porter bundles that access a Kubernetes cluster when running can now be installed as normal, once the Credential Set is generated/edited to use the KinD kubeconfig.

Here we’ll generate credentials and install the MySQL bundle:

 $ porter credentials generate
Generating new credential mysql from bundle mysql
==> 1 credentials required for bundle mysql
? How would you like to set credential "kubeconfig"
  file path
? Enter the path that will be used to set credential "kubeconfig"
  /Users/vdice/.kubes/kind/kubeconfig

 $ porter install -c mysql
installing mysql...
executing install action from mysql (bundle instance: mysql)
Install MySQL
...
/usr/local/bin/helm helm install --name porter-ci-mysql bitnami/mysql --version 6.14.2 --replace --set db.name=mydb --set db.user=mysql-admin
NAME:   porter-ci-mysql
LAST DEPLOYED: Wed Jul 15 15:11:43 2020
NAMESPACE: default
STATUS: DEPLOYED
...
execution completed successfully!