ããã«ã¡ã¯ãNecoããã¸ã§ã¯ãã®satã§ããä»åã¯Kubernetesã¯ã©ã¹ã¿ãæ軽ã«ä½ããkindã¨ãããã¼ã«ãç´¹ä»ãã¾ããkindã¯Kubernetes In Dockerã®ç¥ã§ãã
æ¬è¨äºã®è¦ç´
- kindã¨ã¯Kubernetesã¯ã©ã¹ã¿ãç°¡åã«ä½ãããã¼ã«
- ã¤ã³ã¹ãã¼ã«ãããã³ã¯ã©ã¹ã¿ä½æããããããã£ã1ã³ãã³ããå®è¡ããã ãã§å®äº
- ä»ã®é¡ä¼¼ãã¼ã«ã«ã¯åå¨ããªããã«ããã¼ãã¯ã©ã¹ã¿ä½ææ©è½ããã
- Kubernetesã®å ¬å¼ããã¸ã§ã¯ããã¤ãKubernetesãã®ãã®ã®ãã¹ãã«ãç¨ãããã¦ãããããå®ç¸¾ãå°æ¥æ§ã¯åå
ä¿®æ£å±¥æ´
- 2019/7/04: ãã¯ã©ã¹ã¿ã®è¨å®ãå¤æ´ããæ¹æ³ãç¯ã®
apiVersion: kubeadm.k8s.io/v1beta1
ãapiVersion: kubeadm.k8s.io/v1beta2
ã«ä¿®æ£ãã¾ãã
kindã¨ã¯
Kubernetesã¯è¤éãªã½ããã¦ã§ã¢ãªã®ã§ãèªåã§ä¸ããæ§ç¯ããã®ã¯é常ã«å¤§å¤ã§ãã*1ã ãã®ãããä¸ã®ä¸ã«ã¯ãã¼ã«ã«ç°å¢ã§ã¨ããããKubernetesã使ã£ã¦ã¿ããã¨ãããããªç¨éã§minikubeãmicrok8sã¨ãã£ãæ§ã ãªãã¼ã«ãåå¨ãã¦ãããkindããã®ä¸ã¤ã§ãã ããããæ§ç¯ã§ããKubernetesã¯ã©ã¹ã¿ããµãã¼ãããæ©è½ãç°ãªãããã«ä¸é·ä¸çã§ãããã©ãã使ãã¹ããã¯ä½¿ãããæ©è½ã好ã¿ã«ãã£ã¦å¤ããã¾ãã ãã ãkindã«ã¯ãã«ããã¼ãã¯ã©ã¹ã¿ãä½ããã¨ããä»ã®ãã¼ã«ã«ã¯ç¡ãç¹é·ãããã¾ãã
kindã¯Kubernetesã®å ¬å¼ãã¼ã«ã§ãããv1.11以éã§ã¯Kubernetesãã®ãã®ããã¹ãããããã«ä½¿ããã¦ãã¾ãããã®ããkindã¯å®ç¸¾ã¨å°æ¥æ§ãåªãã¦ããã¨ããã¾ãã
kindã¯Kubernetesããã®å¨è¾ºãã¼ã«ã«ã¾ã¤ããåé¡ã«ã¤ãã¦ããããã®ã³ãã¥ããã£ã«issueãçºè¡ããã¨ãã«ãæç¨ã§ãããªããªãã°ç¬èªãã¼ã« *2ãªã©ã®ä¸éçã«ã¯ ãã¤ãã¼ãªæ¹æ³ã§æ§ç¯ããã¯ã©ã¹ã¿ä¸ã§èµ·ããåé¡ã¯ ãå½è©²ã½ããã¦ã§ã¢ã®åé¡ã§ã¯ãªãããã¾ãã¯æåã©ããã®ãã¼ã«ã使ã£ã¦æ§ç¯ããã¯ã©ã¹ã¿ã§åç¾ããã¦ã»ããã ã¨è¨ããããã¨ãããããããã§ããKubernetesã®å ¬å¼ãã¼ã«ã§ããã°ãã®ãããªåé¡ã¯èµ·ãã«ããã§ãããã
ã§ã¯ããããã¯kindã®ä½¿ãæ¹ãããã³åä½ã®ããã¿ã«ã¤ãã¦èª¬æãã¾ãã
使ãæ¹
å¿ è¦æ¡ä»¶
kindã®ã¤ã³ã¹ãã¼ã«ãããããã«ã¯æ¬¡ã®æ¡ä»¶ãæºããã¦ããå¿ è¦ãããã¾ãã
- kubectlãã¤ã³ã¹ãã¼ã«ããã¦ãã
- dockerãã¤ã³ã¹ãã¼ã«ããã¦ããããã¤ãkindã使ãã¦ã¼ã¶ãã使ããããã«ãªã£ã¦ãã(ãã¨ãã°dockerã°ã«ã¼ãã«å ¥ããããªã©)
ã¤ã³ã¹ãã¼ã«æ¹æ³
次ã®ã³ãã³ããå®è¡ãã¾ãã
$ GO111MODULE="on" go get sigs.k8s.io/kind@<kindã®ãã¼ã¸ã§ã³çªå·>
ãã¨ãã°æ¬æ¸å·çæç¹ã«ãããææ°çã§ããv0.4.0ãå©ç¨ããã«ã¯æ¬¡ã®ããã«å®è¡ãã¾ãã
$ GO111MODULE="on" go get sigs.k8s.io/[email protected]
æãåç´ãªã¯ã©ã¹ã¿ãä½ãæ¹æ³
次ã®ã³ãã³ããå®è¡ãã¾ãã
$ kind create cluster [---name=<ã¯ã©ã¹ã¿åãç¡æå®ã®å ´åã¯ã¯ã©ã¹ã¿åã"kind"ã«ãªã>]
ä½ã£ãã¯ã©ã¹ã¿ã«ãã¼ã«ã«ç°å¢ããã¢ã¯ã»ã¹ã§ããããã«ããããã«ã¯ä»¥ä¸ã®ã³ãã³ããå®è¡ãã¾ãã
$ export KUBECONFIG="$(kind get kubeconfig-path [--name=<ã¯ã©ã¹ã¿å>])"
ã¯ã©ã¹ã¿åã®ããã©ã«ãã¯kind
ã§ãã
ä¸è¨ã®ããã«--loglevelãªãã·ã§ã³ãä»ããã¨å®è¡æã«è©³ç´°ãªãã°ãåºåã§ãã¾ãã
$ kind create cluster --loglevel debug
--wait
ãªãã·ã§ã³ãæå®ããã¨ããã¼ããReadyç¶æ
ã«ãªãã¾ã§å¾
ã¤ããã«ãªãã¾ã(ããã©ã«ãã§ã¯å¾
ããªã)ã
$ kind create cluster --wait 100s
è¤æ°ã¯ã©ã¹ã¿ãä½ãæ¹æ³
foo, barã¨ããäºã¤ã®ã¯ã©ã¹ã¿ãç«ã¡ä¸ããã«ã¯æ¬¡ã®ããã«ãã¾ãã
$ kind create cluster --name=foo Creating cluster "foo" ... ... $ kind get clusters foo $ kind create cluster --name=bar Creating cluster "bar" ... ... $ kind get clusters bar foo $ ls -1 .kube/kind-config-* .kube/kind-config-bar .kube/kind-config-foo $
ãã«ããã¼ãã¯ã©ã¹ã¿ãä½ãæ¹æ³
kindã®è¨å®ãã¡ã¤ã«ãä½ãã°ãã«ããã¼ãã¯ã©ã¹ã¿ãä½ãã¾ãã次ã«ç¤ºãã®ã¯ã³ã³ããã¼ã«ãã¬ã¼ã³ãã¼ã1ã¤ã¨ã¯ã¼ã«ã¼ãã¼ã3ã¤ã®ã¯ã©ã¹ã¿ãä½ãããã®è¨å®ãã¡ã¤ã«ã§ãã
kind: Cluster apiVersion: kind.sigs.k8s.io/v1alpha3 # 1 control plane node and 3 workers nodes: # the control plane node config - role: control-plane # the three workers - role: worker - role: worker - role: worker
nodes
è¦ç´ 以ä¸ãå¤æ´ããã°ãã¼ãæ°ãèªç±ã«å¤ãããã¾ãã
ä¸è¨è¨å®ãã¡ã¤ã«ã使ã£ã¦ãã«ããã¼ãk8sã¯ã©ã¹ã¿ãä½ãã«ã¯æ¬¡ã®ããã«ãã¾ãã
$ kind create cluster --name multi --config multinode.yaml Creating cluster "multi" ... ... Cluster creation complete. You can now use the cluster with: export KUBECONFIG="$(kind get kubeconfig-path --name="multi")" kubectl cluster-info $ export KUBECONFIG="$(kind get kubeconfig-path --name="multi")" $ kubectl get node NAME STATUS ROLES AGE VERSION multi-control-plane Ready master 10m v1.15.0 multi-worker Ready <none> 9m44s v1.15.0 multi-worker2 Ready <none> 9m44s v1.15.0 multi-worker3 Ready <none> 9m44s v1.15.0 $
Kubernetesã®ãã¼ã¸ã§ã³ãæå®ããæ¹æ³
kindãã¤ã³ã¹ãã¼ã«ããKubernetesã®ãã¼ã¸ã§ã³ã¯kindã®ãã¼ã¸ã§ã³ãã¨ã«ããã©ã«ãå¤ã決ã¾ã£ã¦ãã¾ã(kind v0.4.0ã§ã¯Kubernetes v1.15.0, kind v0.3.0ã§ã¯kubernetes v1.14.2ããªã©)ã 次ã®ããã«ã¯ã©ã¹ã¿è¨å®ãã¡ã¤ã«ã®kubeadmConfigPatchesã«ãã¼ã¸ã§ã³ãæå®ãããã¨ã§ãä»»æã®ãã¼ã¸ã§ã³ã®Kubernetesã使ãã¾ãã
kind: Cluster apiVersion: kind.sigs.k8s.io/v1alpha3 kubeadmConfigPatches: - | apiVersion: kubeadm.k8s.io/v1beta2 kind: ClusterConfiguration metadata: name: config kubernetesVersion: v1.14.3 networking: serviceSubnet: 10.0.0.0/16
kindãä½ãã¯ã©ã¹ã¿ãæ§æããåã ã®ãã¼ãã¯Dockerã³ã³ããã¨ãã¦è¡¨ç¾ããã¾ã(詳細ã¯å¾è¿°)ããããã³ã³ããã®ã¤ã¡ã¼ã¸ãå¤æ´ããã«ã¯æ¬¡ã®ããã«ã¯ã©ã¹ã¿ä½ææã«ã¤ã¡ã¼ã¸ãæå®ãã¾ãã
$ kind create cluster --image kindest/node:v1.14.3
æå®ã§ããã¤ã¡ã¼ã¸ã®ä¸è¦§ã¯ãã¡ããããããã ããã
ãã¼ãã³ã³ããã«ã¢ã¯ã»ã¹ããæ¹æ³
以ä¸ã®ããã«docker execã§ã³ã³ããã¼ã«ãã¬ã¼ã³ãã¼ãã«å ¥ãã¾ãã
$ docker exec -it kind-control-plane bash
ã³ã³ããã¼ã«ãã¬ã¼ã³ãã¼ã
å
ã§ã¯ãkubeadm
, ctr
, crictl
ãªã©ã®ã³ãã³ããå©ç¨ã§ãã¾ãã
ãã°ãè¦ãæ¹æ³
kubectl logsã«ãã£ã¦kube-apiserverãkube-schedulerã®ãã°ã確èªã§ãã¾ãã
kubectl logs -n kube-system kube-scheduler-kind-control-plane
次ã®ã³ãã³ããå®è¡ããã¨åã³ã³ãã¼ãã³ãã®ãã°ãåéãã¦ãã¼ã«ã«ãã·ã³ã®/tmp
以ä¸ã«æ¸ãåºãã¦ããã¾ãã
$ kind export logs Exported logs to: /tmp/486658715
kube-schedulerãpodã¨ãã¦ç«ã¡ä¸ãã£ã¦ããªãå ´åã¯ããã®æ¹æ³ã§ãã°ãè¦ããã¨ãã§ãã¾ãã
ã¯ã©ã¹ã¿ã®è¨å®ãå¤æ´ããæ¹æ³
kindã¯å
é¨ã§kustomizeã使ã£ã¦ãããè¨å®ãã¡ã¤ã«å
ã«kubeadmConfigPatches
ãããã³kubeadmConfigPatchesJson6902
ã¨ãããã®ãå®ç¾©ã§ãã¾ãã
å
容ã¯ããããkustomizeã®patchesStrategicMerge
ã¨patchesJson6902
ã«ç¸å½ãã¾ãã
ããã«ãã£ã¦kindãå
é¨ã§å©ç¨ãã¦ããkubeadmã®è¨å®ãã¡ã¤ã«ã«ããããå½ã¦ããã¾ãã
ä¾ãã°kube-schedulerã®configãªãã·ã§ã³ãæå®ãããå ´åã¯ãä¸è¨ã®ããã«è¨è¿°ã§ãã¾ãã
kind: Cluster apiVersion: kind.sigs.k8s.io/v1alpha3 # patch the generated kubeadm config with some extra settings kubeadmConfigPatches: - | apiVersion: kubeadm.k8s.io/v1beta2 kind: ClusterConfiguration metadata: name: config scheduler: extraVolumes: - name: "config" hostPath: /mnt/host/scheduler mountPath: /var/lib/scheduler readOnly: true extraArgs: config: /var/lib/scheduler/scheduler-config.yaml
ãã¼ã«ã«ãã·ã³ä¸ã®ãã¡ã¤ã«ãã³ã³ããã¼ã«ãã¬ã¼ã³ã§å©ç¨ãããå ´åã¯ãextraMounts
ã使ãã¾ãã
kind: Cluster apiVersion: kind.sigs.k8s.io/v1alpha3 nodes: - role: control-plane extraMounts: - containerPath: /mnt/host hostPath: /tmp/path/to
kindã¨kubeadmã®è¨å®ãã¡ã¤ã«ã«ã¤ãã¦ã®è©³ç´°ã¯ããããã®godocãåç §ãã¦ãã ããã
åä½ã®ããã¿
å®è¡æã«ã¯ã³ã³ããã¼ã«ãã¬ã¼ã³ãã¼ãã¨ã¯ã¼ã«ã¼ãã¼ãã«å¯¾å¿ããDockerã³ã³ãããããããèµ·åããã¦ãã¾ããããããdocker ps
ã§ç¢ºèªã§ãã¾ãã
$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES df7d631bb6a8 kindest/node:v1.14.1 "/usr/local/bin/entrâ¦" 2 hours ago Up 2 hours kind-worker3 4da3bf000b00 kindest/node:v1.14.1 "/usr/local/bin/entrâ¦" 2 hours ago Up 2 hours kind-worker2 772938eaed30 kindest/node:v1.14.1 "/usr/local/bin/entrâ¦" 2 hours ago Up 2 hours 37735/tcp, 127.0.0.1:37735->6443/tcp kind-control-plane 957d78a62abd kindest/node:v1.14.1 "/usr/local/bin/entrâ¦" 2 hours ago Up 2 hours kind-worker
kindã¯ãããã®ã³ã³ããã®ä¸ã§systemdãµã¼ãã¹ã¨ãã¦kubeletãå®è¡ãã¦ãã¾ãã
$ docker exec -it kind-control-plane systemctl status kubelet.service â kubelet.service - kubelet: The Kubernetes Node Agent Loaded: loaded (/kind/systemd/kubelet.service; enabled; vendor preset: enabled) Drop-In: /etc/systemd/system/kubelet.service.d ââ10-kubeadm.conf Active: active (running) since Fri 2019-06-28 02:38:32 UTC; 1h 52m in ago
etcd, kube-apiserver, kube-scheduler, kube-controller-managerã¯ã Static Podã¨ãã¦Kubernetesä¸ã«ã»ã«ããã¹ãããã¦ãã¾ãã kube-proxy, weave, corednsã¯ãDeploymentãDaemonSetã¨ãã¦Kubernetesä¸ã«ãããã¤ããã¦ãã¾ãã
$ kubectl get all -A NAMESPACE NAME READY STATUS RESTARTS AGE kube-system pod/coredns-fb8b8dccf-4gwkb 1/1 Running 0 113m kube-system pod/coredns-fb8b8dccf-xgm69 1/1 Running 0 113m kube-system pod/etcd-kind-control-plane 1/1 Running 0 112m kube-system pod/kube-apiserver-kind-control-plane 1/1 Running 0 112m kube-system pod/kube-controller-manager-kind-control-plane 1/1 Running 0 112m kube-system pod/kube-proxy-cqh6s 1/1 Running 0 113m kube-system pod/kube-proxy-frxz6 1/1 Running 0 113m kube-system pod/kube-proxy-j9q2r 1/1 Running 0 113m kube-system pod/kube-proxy-kn7xd 1/1 Running 0 113m kube-system pod/kube-scheduler-kind-control-plane 1/1 Running 0 112m kube-system pod/weave-net-69crj 2/2 Running 0 113m kube-system pod/weave-net-f8fqv 2/2 Running 0 113m kube-system pod/weave-net-lc7tz 2/2 Running 0 113m kube-system pod/weave-net-q6k67 2/2 Running 0 113m NAMESPACE NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE default service/kubernetes ClusterIP 10.0.0.1 <none> 443/TCP 113m kube-system service/kube-dns ClusterIP 10.0.0.10 <none> 53/UDP,53/TCP,9153/TCP 113m NAMESPACE NAME DESIRED CURRENT READY UP-TO-DATE AVAILABLE NODE SELECTOR AGE kube-system daemonset.apps/kube-proxy 4 4 4 4 4 <none> 113m kube-system daemonset.apps/weave-net 4 4 4 4 4 <none> 113m NAMESPACE NAME READY UP-TO-DATE AVAILABLE AGE kube-system deployment.apps/coredns 2/2 2 2 113m NAMESPACE NAME DESIRED CURRENT READY AGE kube-system replicaset.apps/coredns-fb8b8dccf 2 2 2 113m
ãããã«
ä»åã¯Kubernetesã®å ¥éããã¹ããããã³Kubernetesãªã©ã®OSSã¸ã®issueçºè¡ã«ããã¦ä¾¿å©ãªkindã¨ãããã¼ã«ãç´¹ä»ãã¾ããã Necoã«ããã¦ãèªç¤¾è£½ãã¼ã«ã«ä¾åããªããã¹ããããããã«ã¯ããã¾ã§microk8sã使ã£ã¦ããã®ã§ããã ç¾å¨ã¯ãã«ãã¯ã©ã¹ã¿ä½ææ©è½ã«æ³¨ç®ãã¦kindã«ç§»è¡ä¸ã§ãããã¾ã®ã¨ãã大å¤ä¾¿å©ã«ä½¿ãã¦ãã¾ãã æ¬è¨äºãèªããã¨ã«ãã£ã¦Kubernetesã®ã¦ã¼ã¶ãããã³kindã«ãã£ã¦Kubernetesã使ã£ãã·ã¹ãã ã®éçºã楽ã«ãªã人ãå¢ããã°å¹¸ãã§ãã