Using Kind - CAAPIM/layer7-operator GitHub Wiki

Using Kind

To avoid impacting your existing Kubernetes Cluster you can optionally use Kind (Kubernetes in Docker).

Note: Kind is a great tool to run local Kubernetes clusters using Docker but your mileage may vary based on your available hardware (mac/pc) and company policies. One common solution to problems some users run into is to create a virtual machine (Ubuntu) locally or remotely with these tools installed.

Prerequisites

Install Kind

Please follow this guide to install Kind on your system.

Kind Configuration

This configuration will work if your docker engine is running locally.

Save this to a file called kind-config.yaml

kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
# networking:
#   apiServerAddress: "<virtual-machine-address>"
#   apiServerPort: 6443
nodes:
- role: control-plane
  kubeadmConfigPatches:
  - |
    kind: InitConfiguration
    nodeRegistration:
      kubeletExtraArgs:
        node-labels: "ingress-ready=true"
  extraPortMappings:
  - containerPort: 80
    hostPort: 80
    protocol: TCP
  - containerPort: 443
    hostPort: 443
    protocol: TCP

Note: if you have a virtual machine that you would like to access remotely uncomment the following lines and set the apiServerAddress to the IP Address of your virtual machine.

# networking:
#   apiServerAddress: "<virtual-machine-address>"
#   apiServerPort: 6443

example

networking:
  apiServerAddress: "192.168.1.40"
  apiServerPort: 6443

Deploy a Kind Cluster

kind create cluster --config /path/to/kind-config.yaml --name layer7

output

Creating cluster "layer7" ...
 ✓ Ensuring node image (kindest/node:v1.29.1) đŸ–ŧ 
 ✓ Preparing nodes đŸ“Ļ  
 ✓ Writing configuration 📜 
 ✓ Starting control-plane đŸ•šī¸ 
 ✓ Installing CNI 🔌 
 ✓ Installing StorageClass 💾 
Set kubectl context to "kind-layer7"
You can now use your cluster with:

kubectl cluster-info --context kind-layer7

Have a nice day! 👋

Confirm access

kubectl version

output

Client Version: v1.29.1
Kustomize Version: v5.0.4-0.20230601165947-6ce0bf390ce3
Server Version: v1.29.1

if you receive output that looks like this please update your Kubernetes Client (kubectl) to within the supported minor version skew

Client Version: v1.29.1
Kustomize Version: v5.0.4-0.20230601165947-6ce0bf390ce3
Server Version: v1.27.6+b49f9d1
WARNING: version difference between client (1.29) and server (1.27) exceeds the supported minor version skew of +/-1

Use Kind remotely

If you would like to interact with your Kind Cluster remotely, you will need kubectl on your local machine and the kubeconfig from the Kind Cluster.

You can retrieve this by running the following command on the virtual machine

kind get kubeconfig --name layer7 > kind-kubeconfig

Copy the contents of kind-kubeconfig to your local machine and run the following command to test connectivity

kubectl --kubeconfig ./path/to/kind-kubeconfig get all

output

NAME                 TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
service/kubernetes   ClusterIP   10.96.0.1    <none>        443/TCP   4h18m

The default path kubectl uses to find kubeconfig is $HOME/.kube/config, note that this is different on Windows

If you already have a kubeconfig in the default location and do not wish to replace or modify it you can set the KUBECONFIG environment variable for your current shell which will remove the need to specify --kubeconfig with each kubectl command, you will need to do this each time you open a new shell.

Cleanup

Removing the Kind Cluster will remove everything that you have previously created or deployed to your Kind Cluster using Kubectl

kind delete cluster --name layer7
âš ī¸ **GitHub.com Fallback** âš ī¸