15
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Docker Desktop for MacのKubernetesを使う

Last updated at Posted at 2019-06-13

概要

Docker Desktop for MacにKubernetesが用意されているので、使ってみる。

目次

Installation

以下のサイトの「Get Docker Desktop for Mac (Edge)」からDockerをダウンロードしてインストールする。
https://hub.docker.com/editions/community/docker-ce-desktop-mac

Screen Shot 2019-06-08 at 11.32.41.png

kubernetesをインストール

「Enable kubernetes」と「Show system containers(advanced)」の2つにチェックをいれ、Applyをクリック
Screen Shot 2019-06-09 at 18.15.50.png

installをクリック
Screen Shot 2019-06-09 at 18.15.55.png

installが完了するまで待つ
Screen Shot 2019-06-09 at 18.15.59.png

install完了
Screen Shot 2019-06-09 at 18.22.43.png

kubernetesのcontextをdocker-for-desktopに切り替える

$ kubectl config use-context docker-for-desktop

もしくは

Screen Shot 2019-06-09 at 18.29.33.png

確認

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」になっていない。
Screen Shot 2019-06-09 at 18.22.43 copy.png

Docker for MacのAdvancedの設定で、リソースの上限を変更する。
Apply & Restartをクリック。

Screen Shot 2019-06-09 at 18.25.06.png

これで、「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をクリック
Screen Shot 2019-06-09 at 18.26.27.png

これでkubernetesのインストールをやり直す。

参考

15
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
15
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?