DEV Community

Roberto Conte Rosito
Roberto Conte Rosito

Posted on • Originally published at blog.robertoconterosito.it on

Deploy a local kind cluster

This guide will help you throught the process of deploying a local kind cluster.

Kind is a tool for running local Kubernetes clusters using Docker container “nodes”. Kind was primarily designed for testing Kubernetes itself, but may be used for local development or CI.

Prerequisites

This guide assumes you have alreay installed:

Create a cluster

Create a kind config file called kind-config.yaml with the following content:

kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
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

Enter fullscreen mode Exit fullscreen mode

Then create the cluster using the following command:

kind create cluster --config kind-config.yaml

Enter fullscreen mode Exit fullscreen mode

The configured cluster is ready to accept requests on port 80 and 443.

Install ingress controller

By default k8s does not have an ingress controller installed. To install the ingress controller run the following command:

kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/provider/kind/deploy.yaml

Enter fullscreen mode Exit fullscreen mode

This will install the nginx ingress controller in the cluster (the most used ingress controller right now, but you can install many other, the only thing you have to do is to change the ingressClassName in your ingress resources).

Test the cluster

To test the cluster you can create a simple deployment and a service:

kubectl run hello \
 --expose \
 --image nginxdemos/hello:plain-text \
 --port 80

Enter fullscreen mode Exit fullscreen mode

Then create a file called ingress.yaml with the following content:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
 name: hello
spec:
 rules:
 - host: hello.robertoconterosito.it
 http:
 paths:
 - pathType: ImplementationSpecific
 backend:
 service:
 name: hello
 port:
 number: 80

Enter fullscreen mode Exit fullscreen mode

Then apply the ingress resource:

kubectl apply -f ingress.yaml

Enter fullscreen mode Exit fullscreen mode

Now you can test the ingress resource using the following command:

curl -H "Host: hello.robertoconterosito.it" localhost

Enter fullscreen mode Exit fullscreen mode

Top comments (0)