Skip to content

Instantly share code, notes, and snippets.

@akaanirban
Created April 23, 2021 22:47
Show Gist options
  • Save akaanirban/2731a4f70e6da0f28a78587dc3f410e3 to your computer and use it in GitHub Desktop.
Save akaanirban/2731a4f70e6da0f28a78587dc3f410e3 to your computer and use it in GitHub Desktop.
How to set up Kind with multiple nodes, and Connect from a remote computer

The following shows how to setup Kind locally with multiple nodes and connect to it from a remote computer.

WARNING: DO NOT DO THIS UNLESS YOU KNOW AHT YOU ARE DOING. OR UNLESS YOU ARE IN A SUBNET. KIND HAS VERY LITTLE SECURITY AND EXPOSING IT TO OUTSIDE MAY COMPROMISE YOUR SYSTEM!

Step 1:

  • Install Kind in the local computer. Lets assume the ip of the local computer is a.b.c.d and you want the kubernetes control plane to run on port 4321.
  • Lets further suppose you want a kind deployment with 1 master node and 3 worker node. Some of this is taken from kubernetes-sigs/kind#873 (comment) .
  • Make a file kind_node_config and paste the following in it
    # four node (three workers) cluster config
    kind: Cluster
    apiVersion: kind.x-k8s.io/v1alpha4
    networking:
      apiServerAddress: a.b.c.d
      apiServerPort: 4321
      serviceSubnet: 10.0.0.0/16
    nodes:
      - role: control-plane
      - role: worker
      - role: worker
      - role: worker
    
    This is the configuration to create 3 workers, 1 master. This will expose the kubernetes api server to run on a.b.c.d:4321, which for kind, normally always is configured to run in server 127.0.0.1 and hence remote connection is not possible usually.
  • The do : kind create cluster --config kind_worker
  • This will create the kind cluster.
    Creating cluster "kind" ...
    βœ“ Ensuring node image (kindest/node:v1.19.1) πŸ–Ό
    βœ“ Preparing nodes πŸ“¦ πŸ“¦ πŸ“¦ πŸ“¦  
    βœ“ Writing configuration πŸ“œ 
    βœ“ Starting control-plane πŸ•ΉοΈ 
    βœ“ Installing CNI πŸ”Œ 
    βœ“ Installing StorageClass πŸ’Ύ 
    βœ“ Joining worker nodes 🚜 
    Set kubectl context to "kind-kind"
    You can now use your cluster with:
    
    kubectl cluster-info --context kind-kind
    
    Have a question, bug, or feature request? Let us know! https://kind.sigs.k8s.io/#community πŸ™‚
    
  • Check your cluster infor by : kubectl cluster-info
    Kubernetes control plane is running at https://a.b.c.d:4321
    KubeDNS is running at https://a.b.c.d:4321/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
    

Step 2: Configure the remote computer to connect to Kind.

  • Basically you would have to copy over the kube config yaml file from the local computer to the remote.
  • From the remote computer, assuming you have ssh access do the following:
    cd ~
    mkdir .kube
    cd .kube
    scp <username>@a.b.c.d:4321:~/.kube/config ./
    
  • Do kubectl cluster-info to verify you can connect to the kind cluster from the remote computer.
    Kubernetes control plane is running at https://a.b.c.d:4321
    KubeDNS is running at https://a.b.c.d:4321/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment