This page looks best with JavaScript enabled

Use Kind to provision Kubernetes, run KubeSphere anywhere

 ·  ☕ 5 min read  ·  ✍️ Feynman

What is kind

kind, Kubernetes IN Docker - local clusters for testing Kubernetes. kind is an open source 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. kind bootstraps each “node” with kubeadm.

Differences between kind and kubekey

Generally, kind is similar to kubekey, both are used to provision a Kubernetes cluster to the target machines. Specifically, kind has unique scenarios and advantages when comparing with KK, because kind has good cross-platform support, it can provision a standard Kubernetes cluster in Mac/Win/Linux, it’s very easy to run KubeSphere anywhere.

kind runs Kubernetes in a Docker container, with a lightweight runtime containerd. kind packages the necessary dependencies (ebtables, socat, ipset, conntrack, etc.) into one docker image, which gracefully avoid the dependency problem. In addition, Kind will provision a default StorageClass with local storage built in. Typically, for users who want to install KubeSphere for a testing or development in their notebook, kind can used to provision both Kubernetes and KubeSphere in minutes.

My Environment

CentOS Linux release 7.6 on QingCloud Platform

Prerequisite

Download Kind

curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.8.1/kind-$(uname)-amd64
chmod +x ./kind
mv ./kind /some-dir-in-your-PATH/kind # e.g. mv ./kind /usr/local/bin/kind

Use Kind to Provision Kubernetes

Important: You have to configure the following three things in a configuration file for kind. To configure kind cluster creation, you will need to create a YAML config file. This file follows Kubernetes conventions for versioning etc.

  1. Create a a YAML config file:
vi config.yaml
  1. Since the APIServer is only listening for 127.0.0.1, which means that APIServer cannot be accessed outside of the Kubernetes cluster which is provisioned by Kind. After creating a cluster, if you want to use kubectl to interact with the Kubernetes cluster by using the kubeconfig, you have to set the filed apiServerAddress to the NodeIP (e.g. 192.168.0.5). See the configuration in networking.

  2. For users who download images slowly from DockerHub, it is recommended to configure the image accelerator. See the configuration in containerdConfigPatches.

  3. Since Kind will provision things in a docker container, it will cause the service exposing problem. Generally, you need to map ports to the host machine. You can map extra ports from the nodes to the host machine with extraPortMappings.

config.yaml

Fill out the config.yaml with the following configuration.

kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
  extraPortMappings:
  - containerPort: 30880  # Enter the port you want to map it from the nodes to the host
    hostPort: 30880  # Enter the port you want to map it from the nodes to the host
    listenAddress: "0.0.0.0" # Optional, defaults to "0.0.0.0"
    protocol: tcp # Defaults to tcp, you can use udp as you need
networking:
  apiServerAddress: "192.168.0.5" # Enter the APIServer IP
containerdConfigPatches:
- |-
  [plugins."io.containerd.grpc.v1.cri".registry.mirrors."docker.io"]
    endpoint = ["https://12345.mirror.aliyuncs.com/"]  # replace it with your own image accelerator
  1. To specify a configuration file when creating a cluster, use the –config flag:
kind create cluster --config config.yaml

  1. Verify the installation:
$ kubectl get pod --all-namespaces

kube-system                    coredns-66bff467f8-984xp                             1/1     Running             0          58m
kube-system                    coredns-66bff467f8-bh5sm                             1/1     Running             0          58m
kube-system                    etcd-kind-control-plane                              1/1     Running             0          59m
kube-system                    kindnet-2t5rx                                        1/1     Running             0          58m
kube-system                    kube-apiserver-kind-control-plane                    1/1     Running             0          59m
kube-system                    kube-controller-manager-kind-control-plane           1/1     Running             3          59m
kube-system                    kube-proxy-g8mqj                                     1/1     Running             0          58m
kube-system                    kube-scheduler-kind-control-plane                    1/1     Running             3          59m
kube-system                    metrics-server-678d5c87c-x4j5k                       1/1
local-path-storage             local-path-provisioner-bd4bb6b75-xt9zg               1/1     Running             1          58m
  1. As you can find that Kind create a default StorageClass local-path to provision local storage. This is quite convenient for the Pods that need to bind PVC.
$ kubectl get sc
NAME                 PROVISIONER             RECLAIMPOLICY   VOLUMEBINDINGMODE      ALLOWVOLUMEEXPANSION   AGE
standard (default)   rancher.io/local-path   Delete          WaitForFirstConsumer   false                  61m

Install KubeSphere on Kubernetes Cluster

At this point, you have a Kubernetes Cluster provisioned by Kind. Next, this is very easy to install KubeSphere on an existing cluster. Plese refer to To Start Deploying KubeSphere.

Important: KubeSphere v3.0 supports multi-cluster management, you can set the kind cluster as a host or a member cluster as you want. Make sure you configure the cluster role in ClusterRole before deploy KubeSphere. Note that we set the kind cluster as a host in this blog.

cluster-configuration.yaml

···
multicluster:
  clusterRole: none  # host | member | none
···

Import Kind Cluster as host

After you installed KubeSphere on an existing Kubernetes cluster, you can import it to the multi-cluster control plane of KubeSphere. Since we set the kind cluster as a host before, we can easily to import the host cluster itself to KubeSphere.

  1. Obtain the kubeconfig file.
cat $HOME/.kube/config

apiVersion: v1
clusters:
- cluster:
    certificate-authority-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUN5RENDQWJDZ0F3SUJBZ0lCQURBTkJna3Foa2lHOXcwQkFRc0ZBREFWTVJNd0VRWURWUVFERXdwcmRXSmwKY201bGRHVnpNQjRYRFRJd01EY3dOakl6TVRVek9Wb1hEVE13TURjd05ESXpNVFV6T1Zvd0ZURVRNQkVHQTFVRQpBeE1LYTNWaVpYSnVaWFJsY3pDQ0FTSXdEUVlKS29aSWh2Y05BUUVCQlFBRGdnRVBBRENDQVFvQ2dnRUJBTnJoCk45ejNXVkp4cUxudS84UjQ2SWNla04xOENYbTdOUVhBWGhEZ1MvOUszR2RqczQ0NldDQUNxOE5IbDhKYnE5RXEKZkVVMkZmdUZkTnBGNVpBQm9OaXZzR2tOdkV0QVFqTE5nUDdHTjNxb0FuQ3ZLN05teVFvQWdtVjBBM05PRkZGagpPY0NaTi9qQlNoRWtyR1VYRjlFRGR1cUQvbjdmQytGV1RQOFZaL2ozMFNGMkcySWR2cmdnUU5uZXdrbjE3M00xCnNzc0pRNVZncnRNdEVaaXdjN2ZlT0lEbEsyclJ3NzRYWVR0V256V3VCc2tCYnFIbVNzTi9WNlVVS2xpWG1JWWsKL1NvOEhBK2ZmcVZhQmo4ZzluUVJGY2VleTIzWVdxODcyVndNeGF6WDdaQ3NCTGxpelNaQWpPT09uYnRQODRsMQo5K0lIUys0bjVTRXJxcHNlams4Q0F3RUFBYU1qTUNFd0RnWURWUjBQQVFIL0JBUURBZ0trTUE4R0ExVWRFd0VCCi93UUZNQU1CQWY4d0RRWUpLb1pJaHZjTkFRRUxCUUFEZ2dFQkFFSGJHV2FwRlBNb1NscWw2d2ZQbW91K2xyQU0KajF3dE96ZGkxbUt3QWY1Nm1DRkFmYnhaUURrNCtTUmhieFRCKzFRRzF4L3BJQ0liaFdtbE81OXVEUExPeUl3Vgpkb3A0TEFnTUR2Q1A4ZS9OanRzVnNzT0JiUFdqWmpwU3d0V3ArQU5XWXgyd3ZEQWl2SllmeWVGVE5QVGFXUzdkCmsyb1VMTnBXVTN3cGNhMGZ0d3o2aVUzemhOMytLN3FOcWxvRDRJUjlUazVjdWNHWWlQYytJSzl2cWs5aEJrbk8KVjRuWmYxcVMxUmVQQWRiY292SDJLQU5WN1BrbExOendnQWYzT1BzblNYcVRXT1NMNExGQks4SWpaSXZzaDJSRwprWSt6aWV5OGdFYjhXOUdtWDVFOVE3d0oxNHZJSlhxR0pyRVRhaG9aNHc1cUFMSlA2Q25Db05WaEh1ST0KLS0tLS1FTkQgQ0VSVElGSUNBVEUtLS0tLQo=
    server: https://192.168.0.5:42786
  name: kind-kind
contexts:
- context:
    cluster: kind-kind
    user: kind-kind
  name: kind-kind
current-context: kind-kind
kind: Config
preferences: {}
users:
- name: kind-kind
  user:
    client-certificate-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUM4akNDQWRxZ0F3SUJBZ0lJVmZKOHAvOFJUL0F3RFFZSktvWklodmNOQVFFTEJRQXdGVEVUTUJFR0ExVUUKQXhNS2EzVmlaWEp1WlhSbGN6QWVGdzB5TURBM01EWXlNekUxTXpsYUZ3MHlNVEEzTURZeU16RTFORGhhTURReApGekFWQmdOVkJBb1REbk41YzNSbGJUcHRZWE4wWlhKek1Sa3dGd1lEVlFRREV4QnJkV0psY201bGRHVnpMV0ZrCmJXbHVNSUlCSWpBTkJna3Foa2lHOXcwQkFRRUZBQU9DQVE4QU1JSUJDZ0tDQVFFQXdvOWxiV0hWWXVseGNvdkgKT0twZmdQL1dLV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1dFp2bW4xK1NHNnZLcG5RUWJNWUNsWmQzYmE4TXpNSGZvUlN3VU1MMDdVemtiCi0tLS0tRU5EIFJTQSBQUklWQVRFIEtFWS0tLS0tCg==
  1. Back to KubeSphere, click Add Cluster.

  1. Fill out the cluster name, and choose the Tag and Provider as you want, then click Next.

  1. Copy and paste the kubeconfig to the multi-cluster control plane of KubeSphere:

  2. Keep the Connection Method as Direct connection to Kubernetes cluster. Copy and paste the kubeconfig into the blank, then click Import to import the target cluster into KubeSphere.

  1. Wait for seconds, the cluster will be joined in a while.

  1. Congratulation! When you see the cluster has imported into KubeSphere, you can enjoy it!

Import a member cluster

Same as above, we can continue to import a member cluster into multi-cluster control plane of KubeSphere.

Cool! Wait for seconds, the member cluster dashboard is coming.

Reference

Share on

Feynman Zhou
WRITTEN BY
Feynman
Community Manager, CNCF Ambassador, InfoQ DevOps Editor