Create local Kubernetes clusters using Docker container "nodes" with kind
The complete cluster configuration is located in k8s/kind-config.yaml
kind builds the cluster in containers, so you can restore the cluster by running containers, eg.
docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
24d4a3dc5453 kindest/node:v1.27.3 "/usr/local/bin/entr…" 5 hours ago Up 16 minutes kind-worker2
b1808fa82d59 kindest/node:v1.27.3 "/usr/local/bin/entr…" 5 hours ago Up 16 minutes kind-worker
e459cc8a2325 kindest/node:v1.27.3 "/usr/local/bin/entr…" 5 hours ago Up 16 minutes 0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp, 127.0.0.1:43813->6443/tcp kind-control-plane
d1dfbc732685 kindest/node:v1.27.3 "/usr/local/bin/entr…" 5 hours ago Up 16 minutes kind-worker4
125a4ffe7e8b kindest/node:v1.27.3 "/usr/local/bin/entr…" 5 hours ago Up 16 minutes kind-worker3Documentation kind
# For AMD64 / x86_64
[ $(uname -m) = x86_64 ] && curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.20.0/kind-linux-amd64
# For ARM64
[ $(uname -m) = aarch64 ] && curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.20.0/kind-linux-arm64
chmod +x ./kind
sudo mv ./kind /usr/local/bin/kindmake helphelp - List available tasks
install-all - Install all (kind k8s cluster, Nginx ingress, MetaLB, demo workloads)
install-all-no-demo-workloads - Install all (kind k8s cluster, Nginx ingress, MetaLB)
create-cluster - Create k8s cluster
export-cert - Export k8s keys(client) and certificates(client, cluster CA)
k8s-dashboard - Install k8s dashboard
nginx-ingress - Install Nginx ingress
metallb - Install MetalLB load balancer
deploy-app-nginx-ingress-localhost - Deploy httpd web server and create an ingress rule for a localhost (http://demo.localdev.me:80/), Patch ingress-nginx-controller service type -> LoadBlancer
deploy-app-helloweb - Deploy helloweb
deploy-app-golang-hello-world-web - Deploy golang-hello-world-web app
deploy-app-foo-bar-service - Deploy foo-bar-service app
deploy-kube-prometheus-stack - Deploy kube-prometheus-stack
delete-cluster - Delete K8s cluste
Make sure you have all the necessary requirements installed
If you already have a kubeconfig, make a backup
[ -e ~/.kube/config ] && mv ~/.kube/config ~/.kube/config_bckAll operations can be performed using make, eg
make install-all-no-demo-workloads./scripts/kind-install-all.shOr you can install each component individually
./scripts/kind-create.sh./scripts/kind-create.shScript creates:
- client.key
- client.crt
- client.pfx
- cluster-ca.crt
Install k8s dashboard
./scripts/kind-add-dashboard.shScript creates file with admin-user token
- dashboard-admin-token.txt
v3.0.0-alpha0
helm repo add kubernetes-dashboard https://kubernetes.github.io/dashboard/
helm upgrade --install kubernetes-dashboard kubernetes-dashboard/kubernetes-dashboard --create-namespace --namespace kubernetes-dashboard
kubectl apply -n kubernetes-dashboard -f ./k8s/dashboard-admin.yaml
export dashboard_admin_token=$(kubectl get secret -n kubernetes-dashboard admin-user-token -o jsonpath="{.data.token}" | base64 --decode)
echo "${dashboard_admin_token}" > dashboard-admin-token.txt
kubectl config set-credentials cluster-admin --token=${dashboard_admin_token}
echo "Dashboard Token: ${dashboard_admin_token}"
export POD_NAME=$(kubectl get pods -n kubernetes-dashboard -l "app.kubernetes.io/name=kubernetes-dashboard,app.kubernetes.io/instance=kubernetes-dashboard" -o jsonpath="{.items[0].metadata.name}")
kubectl -n kubernetes-dashboard port-forward $POD_NAME 8443:8443
xdg-open "https://localhost:8443"
# helm delete kubernetes-dashboard --namespace kubernetes-dashboard
# kubectl delete clusterrolebinding --ignore-not-found=true kubernetes-dashboard
# kubectl delete clusterrole --ignore-not-found=true kubernetes-dashboardv2.x
# kill kubectl proxy if already running
pkill -9 -f "kubectl proxy"
# start new kubectl proxy
kubectl proxy –address=’0.0.0.0′ –accept-hosts=’^*$’ &
# copy admin-user token to the clipboard
cat ./dashboard-admin-token.txt | xclip -i
# open dashboard
xdg-open "http://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/" &In Dashboard UI select "Token' and Ctrl+V
./scripts/kind-add-ingress-nginx.sh./scripts/kind-add-metallb.shhttp://demo.localdev.me:80/
./scripts/kind-deploy-app-nginx-ingress-localhost.sh./scripts/kind-deploy-app-helloweb.sh./scripts/kind-deploy-app-golang-hello-world-web.sh./scripts/kind-deploy-app-foo-bar-service.shAdd prometheus and stable repo to local helm repository
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo add stable https://charts.helm.sh/stable
helm repo updateCreate namespace monitoring to deploy all services in that namespace
kubectl create namespace monitoringInstall kube-prometheus stack
helm install --wait --timeout 15m \
--namespace monitoring --create-namespace \
--repo https://prometheus-community.github.io/helm-charts \
kube-prometheus-stack kube-prometheus-stack --values - <<EOF
kubeEtcd:
service:
targetPort: 2381
kubeControllerManager:
service:
targetPort: 10257
kubeScheduler:
service:
targetPort: 10259
EOF
kubectl apply -f prometheus-ingress.yaml -n monitoring
kubectl --namespace monitoring get pods -l release=kube-prometheus-stackDelete kube-prometheus stack
kubectl delete -f ./k8s/prometheus.yaml./scripts/kind-delete.sh