概要
Docker Desktop for MacにKubernetesが用意されているので、使ってみる。
目次
Installation
以下のサイトの「Get Docker Desktop for Mac (Edge)」からDockerをダウンロードしてインストールする。
https://hub.docker.com/editions/community/docker-ce-desktop-mac
kubernetesをインストール
「Enable kubernetes」と「Show system containers(advanced)」の2つにチェックをいれ、Applyをクリック
kubernetesのcontextをdocker-for-desktopに切り替える
$ kubectl config use-context docker-for-desktop
もしくは
確認
Dockerイメージが生成されたことを確認
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker/kube-compose-controller v0.4.22 cf23dccf65a6 7 weeks ago 35.3MB
docker/kube-compose-api-server v0.4.22 6c3de501d7f3 7 weeks ago 49.9MB
k8s.gcr.io/kube-proxy v1.14.1 20a2d7035165 2 months ago 82.1MB
k8s.gcr.io/kube-apiserver v1.14.1 cfaa4ad74c37 2 months ago 210MB
k8s.gcr.io/kube-scheduler v1.14.1 8931473d5bdb 2 months ago 81.6MB
k8s.gcr.io/kube-controller-manager v1.14.1 efb3887b411d 2 months ago 158MB
k8s.gcr.io/coredns 1.3.1 eb516548c180 4 months ago 40.3MB
k8s.gcr.io/etcd 3.3.10 2c4adeb21b4f 6 months ago 258MB
k8s.gcr.io/pause 3.1 da86e6ba6ca1 17 months ago 742kB
Dockerコンテナが起動していることを確認
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3b188096b0bd eb516548c180 "/coredns -conf /etc…" 3 minutes ago Up 3 minutes k8s_coredns_coredns-fb8b8dccf-ng878_kube-system_6a107d1b-8a97-11e9-a84c-025000000001_2
359156fdde44 eb516548c180 "/coredns -conf /etc…" 4 minutes ago Up 4 minutes k8s_coredns_coredns-fb8b8dccf-w95g9_kube-system_6a0c81f4-8a97-11e9-a84c-025000000001_2
abdcb4770d0d 6c3de501d7f3 "/api-server --kubec…" 4 minutes ago Up 4 minutes k8s_compose_compose-api-6c5bf98cc7-8glcv_docker_94be499a-8a97-11e9-a84c-025000000001_2
e31c3d7678cb cf23dccf65a6 "/compose-controller…" 4 minutes ago Up 4 minutes k8s_compose_compose-6b69ff6b9d-fq42g_docker_94cbe1a4-8a97-11e9-a84c-025000000001_1
c2904b68e97d 20a2d7035165 "/usr/local/bin/kube…" 4 minutes ago Up 4 minutes k8s_kube-proxy_kube-proxy-l7rw8_kube-system_6a73bc5a-8a97-11e9-a84c-025000000001_1
396ab9225126 k8s.gcr.io/pause:3.1 "/pause" 4 minutes ago Up 4 minutes k8s_POD_compose-6b69ff6b9d-fq42g_docker_94cbe1a4-8a97-11e9-a84c-025000000001_1
2ff13073b6bc k8s.gcr.io/pause:3.1 "/pause" 4 minutes ago Up 4 minutes k8s_POD_kube-proxy-l7rw8_kube-system_6a73bc5a-8a97-11e9-a84c-025000000001_1
64c88a251710 k8s.gcr.io/pause:3.1 "/pause" 4 minutes ago Up 4 minutes k8s_POD_compose-api-6c5bf98cc7-8glcv_docker_94be499a-8a97-11e9-a84c-025000000001_1
cd6545b47574 k8s.gcr.io/pause:3.1 "/pause" 4 minutes ago Up 4 minutes k8s_POD_coredns-fb8b8dccf-ng878_kube-system_6a107d1b-8a97-11e9-a84c-025000000001_1
34d746d57933 k8s.gcr.io/pause:3.1 "/pause" 4 minutes ago Up 4 minutes k8s_POD_coredns-fb8b8dccf-w95g9_kube-system_6a0c81f4-8a97-11e9-a84c-025000000001_1
c212db9a78fa cfaa4ad74c37 "kube-apiserver --ad…" 4 minutes ago Up 4 minutes k8s_kube-apiserver_kube-apiserver-docker-desktop_kube-system_ba13c4f05e12c81986f81b0bea31be9f_1
42a9ff8cd93c 8931473d5bdb "kube-scheduler --bi…" 4 minutes ago Up 4 minutes k8s_kube-scheduler_kube-scheduler-docker-desktop_kube-system_f44110a0ca540009109bfc32a7eb0baa_1
b85631911c84 efb3887b411d "kube-controller-man…" 4 minutes ago Up 4 minutes k8s_kube-controller-manager_kube-controller-manager-docker-desktop_kube-system_40f1833ee150c47d0f33cecb02681b1a_1
e8219053ed99 2c4adeb21b4f "etcd --advertise-cl…" 4 minutes ago Up 4 minutes k8s_etcd_etcd-docker-desktop_kube-system_3773efb8e009876ddfa2c10173dba95e_1
cbeea4516f57 k8s.gcr.io/pause:3.1 "/pause" 4 minutes ago Up 4 minutes k8s_POD_kube-apiserver-docker-desktop_kube-system_ba13c4f05e12c81986f81b0bea31be9f_1
ec40c90c38ae k8s.gcr.io/pause:3.1 "/pause" 4 minutes ago Up 4 minutes k8s_POD_kube-scheduler-docker-desktop_kube-system_f44110a0ca540009109bfc32a7eb0baa_1
550ce07216c4 k8s.gcr.io/pause:3.1 "/pause" 4 minutes ago Up 4 minutes k8s_POD_kube-controller-manager-docker-desktop_kube-system_40f1833ee150c47d0f33cecb02681b1a_1
880e9f77a396 k8s.gcr.io/pause:3.1 "/pause" 4 minutes ago Up 4 minutes k8s_POD_etcd-docker-desktop_kube-system_3773efb8e009876ddfa2c10173dba95e_1
k8sのpodを確認
$ kubectl get pods --all-namespaces
NAMESPACE NAME READY STATUS RESTARTS AGE
docker compose-6b69ff6b9d-fq42g 1/1 Running 1 12m
docker compose-api-6c5bf98cc7-8glcv 1/1 Running 2 12m
kube-system coredns-fb8b8dccf-ng878 1/1 Running 2 13m
kube-system coredns-fb8b8dccf-w95g9 1/1 Running 2 13m
kube-system etcd-docker-desktop 1/1 Running 1 12m
kube-system kube-apiserver-docker-desktop 1/1 Running 1 12m
kube-system kube-controller-manager-docker-desktop 1/1 Running 1 12m
kube-system kube-proxy-l7rw8 1/1 Running 1 13m
kube-system kube-scheduler-docker-desktop 1/1 Running 1 12m
k8sのserviceを確認
$ kubectl get services
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 13m
ハマった点
Unable to connect to the server: EOF
kubectl get pods
で以下のエラーが出る。
$ kubectl get pods --all-namespaces
Unable to connect to the server: EOF
おそらく、以下の画像のように右下の部分が、「Kubernetes is starting...」のままで、「Kubernetes is running」になっていない。
Docker for MacのAdvancedの設定で、リソースの上限を変更する。
Apply & Restartをクリック。
これで、「Kubernetes is running」になり、エラーも出なくなった。
$ kubectl cluster-info
Kubernetes master is running at https://localhost:6443
KubeDNS is running at https://localhost:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
これでも「Kubernetes is running」にならない場合は、次項を参照。
いつまで待ってもKubernetes is runningにならない場合
"Kubernetes is starting…" state never ends #2990
~/.kubeを削除
$ rm -rf ~/.kube
右上のResetをクリック -> Reset kubernetes clusterをクリック
これでkubernetesのインストールをやり直す。
- 参考: