WSL2+Docker+Kind

Standard

ref: https://kubernetes.io/blog/2020/05/21/wsl-docker-kubernetes-on-the-windows-desktop/


❯ kubectl version
Client Version: version.Info{Major:"1", Minor:"22", GitVersion:"v1.22.4", GitCommit:"b695d79d4f967c403a96986f1750a35eb75e75f1", GitTreeState:"clean", BuildDate:"2021-11-17T15:48:33Z", GoVersion:"go1.16.10", Compiler:"gc", Platform:"linux/amd64"}
The connection to the server localhost:8080 was refused - did you specify the right host or port?
❯ curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.11.1/kind-linux-amd64
❯ chmod +x ./kind
❯ sudo mv ./kind /usr/local/bin/
❯ kind create cluster --name wslkind
kind: Cluster
Creating cluster "wslkind" ...
 ✓ Ensuring node image (kindest/node:v1.21.1)
 ✓ Preparing nodes
 ✓ Writing configuration
 ✓ Starting control-plane
 ✓ Installing CNI
 ✓ Installing StorageClass
Set kubectl context to "kind-wslkind"
You can now use your cluster with:
 
kubectl cluster-info --context kind-wslkind
 
Not sure what to do next?  Check out https://kind.sigs.k8s.io/docs/user/quick-start/
❯ kubectl cluster-info --context kind-wslkind
Kubernetes control plane is running at https://127.0.0.1:40805
CoreDNS is running at https://127.0.0.1:40805/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
 
To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
❯ kubectl get nodes
NAME                    STATUS   ROLES                  AGE   VERSION
wslkind-control-plane   Ready    control-plane,master   76s   v1.21.1
❯ kubectl get all -A
NAMESPACE            NAME                                                READY   STATUS    RESTARTS   AGE
kube-system          pod/coredns-558bd4d5db-l9sgt                        1/1     Running   0          77s
kube-system          pod/coredns-558bd4d5db-vv86n                        1/1     Running   0          77s
kube-system          pod/etcd-wslkind-control-plane                      1/1     Running   0          86s
kube-system          pod/kindnet-t9g92                                   1/1     Running   0          77s
kube-system          pod/kube-apiserver-wslkind-control-plane            1/1     Running   0          86s
kube-system          pod/kube-controller-manager-wslkind-control-plane   1/1     Running   0          86s
kube-system          pod/kube-proxy-bttgf                                1/1     Running   0          77s
kube-system          pod/kube-scheduler-wslkind-control-plane            1/1     Running   0          86s
local-path-storage   pod/local-path-provisioner-547f784dff-jglwm         1/1     Running   0          77s
 
NAMESPACE     NAME                 TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)                  AGE
default       service/kubernetes   ClusterIP   10.96.0.1    <none>        443/TCP                  93s
kube-system   service/kube-dns     ClusterIP   10.96.0.10   <none>        53/UDP,53/TCP,9153/TCP   91s
 
NAMESPACE     NAME                        DESIRED   CURRENT   READY   UP-TO-DATE   AVAILABLE   NODE SELECTOR            AGE
kube-system   daemonset.apps/kindnet      1         1         1       1            1           <none>                   88s
kube-system   daemonset.apps/kube-proxy   1         1         1       1            1           kubernetes.io/os=linux   91s
 
NAMESPACE            NAME                                     READY   UP-TO-DATE   AVAILABLE   AGE
kube-system          deployment.apps/coredns                  2/2     2            2           91s
local-path-storage   deployment.apps/local-path-provisioner   1/1     1            1           87s
 
NAMESPACE            NAME                                                DESIRED   CURRENT   READY   AGE
kube-system          replicaset.apps/coredns-558bd4d5db                  2         2         2       77s
local-path-storage   replicaset.apps/local-path-provisioner-547f784dff   1         1         1       77s
❯ kubectl get nodes -A
NAME                    STATUS   ROLES                  AGE    VERSION
wslkind-control-plane   Ready    control-plane,master   2m7s   v1.21.1
 
❯ kind delete cluster --name wslkind
Deleting cluster "wslkind" ...
cat << EOF > kind-3nodes.yaml
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
  - role: control-plane
  - role: worker
  - role: worker
EOF
❯ kind create cluster --name wslkindmultinodes --config ./kind-3nodes.yaml
Creating cluster "wslkindmultinodes" ...
 ✓ Ensuring node image (kindest/node:v1.21.1)
 ✓ Preparing nodes
 ✓ Writing configuration
 ✓ Starting control-plane
 ✓ Installing CNI
 ✓ Installing StorageClass
 ✓ Joining worker nodes
Set kubectl context to "kind-wslkindmultinodes"
You can now use your cluster with:
 
kubectl cluster-info --context kind-wslkindmultinodes
 
Thanks for using kind!
❯ kubectl get nodes -A
NAME                              STATUS   ROLES                  AGE   VERSION
wslkindmultinodes-control-plane   Ready    control-plane,master   46s   v1.21.1
wslkindmultinodes-worker          Ready    <none>                 22s   v1.21.1
wslkindmultinodes-worker2         Ready    <none>                 21s   v1.21.1
❯ kubectl get all -A
NAMESPACE            NAME                                                          READY   STATUS    RESTARTS   AGE
kube-system          pod/coredns-558bd4d5db-cvn7x                                  1/1     Running   0          59s
kube-system          pod/coredns-558bd4d5db-fd5v7                                  1/1     Running   0          59s
kube-system          pod/etcd-wslkindmultinodes-control-plane                      1/1     Running   0          67s
kube-system          pod/kindnet-vr9ph                                             1/1     Running   0          59s
kube-system          pod/kindnet-vxfc5                                             1/1     Running   0          51s
kube-system          pod/kindnet-zxns4                                             1/1     Running   0          52s
kube-system          pod/kube-apiserver-wslkindmultinodes-control-plane            1/1     Running   0          67s
kube-system          pod/kube-controller-manager-wslkindmultinodes-control-plane   1/1     Running   0          73s
kube-system          pod/kube-proxy-7rs68                                          1/1     Running   0          51s
kube-system          pod/kube-proxy-hl4sw                                          1/1     Running   0          59s
kube-system          pod/kube-proxy-p9srt                                          1/1     Running   0          52s
kube-system          pod/kube-scheduler-wslkindmultinodes-control-plane            1/1     Running   0          75s
local-path-storage   pod/local-path-provisioner-547f784dff-gh5xn                   1/1     Running   0          59s
 
NAMESPACE     NAME                 TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)                  AGE
default       service/kubernetes   ClusterIP   10.96.0.1    <none>        443/TCP                  74s
kube-system   service/kube-dns     ClusterIP   10.96.0.10   <none>        53/UDP,53/TCP,9153/TCP   73s
 
NAMESPACE     NAME                        DESIRED   CURRENT   READY   UP-TO-DATE   AVAILABLE   NODE SELECTOR            AGE
kube-system   daemonset.apps/kindnet      3         3         3       3            3           <none>                   68s
kube-system   daemonset.apps/kube-proxy   3         3         3       3            3           kubernetes.io/os=linux   73s
 
NAMESPACE            NAME                                     READY   UP-TO-DATE   AVAILABLE   AGE
kube-system          deployment.apps/coredns                  2/2     2            2           73s
local-path-storage   deployment.apps/local-path-provisioner   1/1     1            1           66s
 
NAMESPACE            NAME                                                DESIRED   CURRENT   READY   AGE
kube-system          replicaset.apps/coredns-558bd4d5db                  2         2         2       59s
local-path-storage   replicaset.apps/local-path-provisioner-547f784dff   1         1         1       59s
 
❯ kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.4.0/aio/deploy/recommended.yaml
❯ kubectl get all -n kubernetes-dashboard
NAME                                            READY   STATUS              RESTARTS   AGE
pod/dashboard-metrics-scraper-c45b7869d-btkrh   1/1     Running             0          14s
pod/kubernetes-dashboard-576cb95f94-w6rb4       0/1     ContainerCreating   0          15s
 
NAME                                TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)    AGE
service/dashboard-metrics-scraper   ClusterIP   10.96.171.90   <none>        8000/TCP   15s
service/kubernetes-dashboard        ClusterIP   10.96.51.246   <none>        443/TCP    15s
 
NAME                                        READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/dashboard-metrics-scraper   1/1     1            1           14s
deployment.apps/kubernetes-dashboard        0/1     1            0           15s
 
NAME                                                  DESIRED   CURRENT   READY   AGE
replicaset.apps/dashboard-metrics-scraper-c45b7869d   1         1         1       14s
replicaset.apps/kubernetes-dashboard-576cb95f94       1         1         0       15s
 
❯ kubectl apply -f - <<EOF
apiVersion: v1
kind: ServiceAccount
metadata:
  name: admin-user
  namespace: kubernetes-dashboard
EOF
serviceaccount/admin-user created
❯ kubectl apply -f - <<EOF
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: admin-user
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: cluster-admin
subjects:
- kind: ServiceAccount
  name: admin-user
  namespace: kubernetes-dashboard
EOF
clusterrolebinding.rbac.authorization.k8s.io/admin-user created
 
❯ kubectl -n kubernetes-dashboard describe secret $(kubectl -n kubernetes-dashboard get secret | grep admin-user | awk '{print $1}')
Name:         admin-user-token-vn2ln
Namespace:    kubernetes-dashboard
Labels:       <none>
Annotations:  kubernetes.io/service-account.name: admin-user
              kubernetes.io/service-account.uid: 4b3752b6-b982-4319-b15c-a831d2caed42
Type:  kubernetes.io/service-account-token
Data
====
namespace:  20 bytes
token:      eyJhbGciOiJ......CDO9EIBQ
ca.crt:     1066 bytes
❯ kubectl proxy
Starting to serve on 127.0.0.1:8001

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.