Running Kubernetes-IN-Docker

Karan Singh
3 min readDec 21, 2019

--

The fastest way to launch a Kubernetes cluster locally !!!

Kubernetes in Docker

kind is a tool for running local Kubernetes clusters using Docker containers. It was primarily designed for testing Kubernetes itself, but may be used for local development or CI.

Pre-requisites

  • Docker installed on your local machine
  • Kind binaries (follow the installation instructions)

Deploying k8s Cluster

Let’s deploy a k8s cluster with 1 x controller node and 3 x worker nodes.

  • First, create a cluster config file kind_cluster_config.yaml
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
extraPortMappings:
- hostPort: 30080
containerPort: 30080
- role: worker
- role: worker
- role: worker
  • Let’s create a k8s cluster named cluster-1
kind create cluster --image kindest/node:v1.17.0 --name cluster-1 --config kind_cluster_config.yaml

The output of the cluster creation is shown below

Once the cluster creation is done, we need to set kubernetes context to interact with the cluster

kubectl cluster-info --context kind-cluster-1kubectl get nodes
kubectl get pods -n kube-system
  • You can verify that all k8s nodes are running in Docker containers by issuing docker ps command

Deploying Application on Kind cluster

  • Create an app.yaml file
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: hello-k8s-deployment
labels:
app: hello-k8s
spec:
replicas: 3
selector:
matchLabels:
app: hello-k8s
template:
metadata:
name: hello-k8s-pod
labels:
app: hello-k8s
spec:
containers:
- name: node-hello
image: gcr.io/google-samples/node-hello:1.0
ports:
- containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
name: hello-k8s-service
labels:
app: hello-k8s
spec:
type: NodePort
ports:
- name: hello-k8s-service
port: 8080
targetPort: 8080
nodePort: 30080
selector:
app: hello-k8s
  • Create a new namespace (not mandatory)
kubectl create ns hello-k8s
  • Deploy the app
kubectl -n hello-k8s create -f app.yaml
kubectl -n hello-k8s get all
  • Browse your app on either CLI or Browser
curl http://localhost:30080

That’s All Folks :

KinD makes is dead simple and efficient to run a k8s cluster locally, I believe kind could be a minikube killer and worth giving a try.

--

--

Karan Singh
Karan Singh

Written by Karan Singh

Co-Founder & CTO @ Scogo AI ♦ I Love to solve problems using Tech

No responses yet