Overview
In this post we will review a method to use kind for local development, for example on the personal laptop. Kind stands for Kubernetes IN Docker, and uses docker containers to simulate kubernetes nodes. It is a great tool to replace bare metal kubernetes,which until recently was relatively easy to install, but then with the CRI changes in kubernetes got very complicated.
The steps below explain how to install kind cluster with NGINX based ingress. Then we show how to simplify the communication with the services deployed on the kubernetes cluster.
Install The Kind Binary
Kind is a standalone binary, we just download it:
curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.17.0/kind-linux-amd64
chmod +x ./kind
sudo mv ./kind /usr/local/bin/kind
Create Kind Based Kubernetes Cluster
To install a kubernetes cluster, we use the following:
cat <<EOF | kind create cluster --config=-
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
EOF
This enables binding of ports 80 and 443 on the local machine, which will later be used for communication from the local development machine to the services running on the kubernetes cluster.
Deploy NGINX Ingress
Now we deploy NGINX based ingress, which is the most popular kubernetes ingress.
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/deploy/static/provider/kind/deploy.yaml
sleep 5
kubectl wait --namespace ingress-nginx \
--for=condition=ready pod \
--selector=app.kubernetes.io/component=controller \
--timeout=90s
Load Docker Images
kind load docker-image ${DockerTag}
List Loaded Docker Images
docker exec -it $(kind get clusters | head -1)-control-plane crictl images
Communication With The Services
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ingress-kind
annotations:
nginx.ingress.kubernetes.io/ssl-redirect: "false"
spec:
rules:
- host: my-service-1
http:
paths:
- pathType: ImplementationSpecific
backend:
service:
name: my-service-1
port:
number: 80
- host: my-service-2
http:
paths:
- pathType: ImplementationSpecific
backend:
service:
name: my-service-2
port:
number: 80
127.0.0.1 my-service-1
127.0.0.1 my-service-2
No comments:
Post a Comment