Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
Help us understand the problem. What is going on with this article?

Docker for Mac with Kubernetes

More than 3 years have passed since last update.

概要

Docker for Mac with Kubernetes のBeta版が利用できるようになってましたので、動かしてみました。

image.png

マニュアルはこのへん
https://docs.docker.com/docker-for-mac/#kubernetes

手順

インストール

Docker for MacのEdgeバージョンをインストールする必要があります。

https://store.docker.com/editions/community/docker-ce-desktop-mac

image.png

ファイルのパス
https://download.docker.com/mac/edge/Docker.dmg

インストールして About Docker を見るとこんな感じです。

image.png

サインイン

Dockerにサインインする必要があるので、メニューからサインインします。

image.png

起動

Preferenceから Kubernetes を選択し、 Enable Kubernetes にチェックを入れて、
Apply します。
image.png

kubectlコマンド

Kubernetesが起動すると、 kubectl コマンドが使えるようになってます。

  • 起動前
$ which kubectl
kubectl not found
  • 起動後
$ which kubectl
/usr/local/bin/kubectl

Homebrew等でkubectlを既にインストールしていて、 /usr/local/bin/kubectl がある場合、先に削除しておく必要があるようです。

contextの変更

kubectlのcontextsを確認します。

# kubectl config get-contexts
CURRENT   NAME                                                           CLUSTER                                                        AUTHINFO                                                       NAMESPACE
          docker-for-desktop                                             docker-for-desktop-cluster                                     docker-for-desktop
*         gke_xxxxxxxx_asia-northeast1-a_sasaki-cluster-1      gke_xxxxxxxx_asia-northeast1-a_sasaki-cluster-1      gke_xxxxxxxx_asia-northeast1-a_sasaki-cluster-1
          gke_xxxxxxxx_asia-northeast1-a_sasaki-test-cluster   gke_xxxxxxxx_asia-northeast1-a_sasaki-test-cluster   gke_xxxxxxxx_asia-northeast1-a_sasaki-test-cluster

contextを docker-for-desktop に変更します。

$ kubectl config use-context docker-for-desktop
Switched to context "docker-for-desktop".
$ kubectl config get-contexts
CURRENT   NAME                                                           CLUSTER                                                        AUTHINFO                                                       NAMESPACE
*         docker-for-desktop                                             docker-for-desktop-cluster                                     docker-for-desktop
          gke_xxxxxxxx_asia-northeast1-a_sasaki-cluster-1      gke_xxxxxxxx_asia-northeast1-a_sasaki-cluster-1      gke_xxxxxxxx_asia-northeast1-a_sasaki-cluster-1
          gke_xxxxxxxx_asia-northeast1-a_sasaki-test-cluster   gke_xxxxxxxx_asia-northeast1-a_sasaki-test-cluster   gke_xxxxxxxx_asia-northeast1-a_sasaki-test-cluster

確認

これで使えるようになっています。

$ kubectl describe nodes
Name:               docker-for-desktop
Roles:              master
Labels:             beta.kubernetes.io/arch=amd64
                    beta.kubernetes.io/os=linux
                    kubernetes.io/hostname=docker-for-desktop
                    node-role.kubernetes.io/master=
Annotations:        node.alpha.kubernetes.io/ttl=0
                    volumes.kubernetes.io/controller-managed-attach-detach=true
Taints:             <none>
CreationTimestamp:  Sat, 06 Jan 2018 10:49:55 +0900
Conditions:
  Type             Status  LastHeartbeatTime                 LastTransitionTime                Reason                       Message
  ----             ------  -----------------                 ------------------                ------                       -------
  OutOfDisk        False   Sat, 06 Jan 2018 10:57:45 +0900   Sat, 06 Jan 2018 10:49:44 +0900   KubeletHasSufficientDisk     kubelet has sufficient disk space available
  MemoryPressure   False   Sat, 06 Jan 2018 10:57:45 +0900   Sat, 06 Jan 2018 10:49:44 +0900   KubeletHasSufficientMemory   kubelet has sufficient memory available
  DiskPressure     False   Sat, 06 Jan 2018 10:57:45 +0900   Sat, 06 Jan 2018 10:49:44 +0900   KubeletHasNoDiskPressure     kubelet has no disk pressure
  Ready            True    Sat, 06 Jan 2018 10:57:45 +0900   Sat, 06 Jan 2018 10:49:44 +0900   KubeletReady                 kubelet is posting ready status
Addresses:
  InternalIP:  192.168.65.3
  Hostname:    docker-for-desktop
Capacity:
 cpu:     2
 memory:  1999Mi
 pods:    110
Allocatable:
 cpu:     2
 memory:  1899Mi
 pods:    110
System Info:
 Machine ID:
 System UUID:                4D3CB816-82BD-8F36-8FF2-D448EAF7BF18
 Boot ID:                    99b16caa-794e-4918-ae57-f8dd1c37f723
 Kernel Version:             4.9.60-linuxkit-aufs
 OS Image:                   Docker for Mac
 Operating System:           linux
 Architecture:               amd64
 Container Runtime Version:  docker://17.12.0-ce
 Kubelet Version:            v1.8.2
 Kube-Proxy Version:         v1.8.2
ExternalID:                  docker-for-desktop
Non-terminated Pods:         (7 in total)
  Namespace                  Name                                          CPU Requests  CPU Limits  Memory Requests  Memory Limits
  ---------                  ----                                          ------------  ----------  ---------------  -------------
  docker                     compose-75f8bb4779-rd9b8                      0 (0%)        0 (0%)      0 (0%)           0 (0%)
  kube-system                etcd-docker-for-desktop                       0 (0%)        0 (0%)      0 (0%)           0 (0%)
  kube-system                kube-apiserver-docker-for-desktop             250m (12%)    0 (0%)      0 (0%)           0 (0%)
  kube-system                kube-controller-manager-docker-for-desktop    200m (10%)    0 (0%)      0 (0%)           0 (0%)
  kube-system                kube-dns-545bc4bfd4-rvvzp                     260m (13%)    0 (0%)      110Mi (5%)       170Mi (8%)
  kube-system                kube-proxy-b94gv                              0 (0%)        0 (0%)      0 (0%)           0 (0%)
  kube-system                kube-scheduler-docker-for-desktop             100m (5%)     0 (0%)      0 (0%)           0 (0%)
Allocated resources:
  (Total limits may be over 100 percent, i.e., overcommitted.)
  CPU Requests  CPU Limits  Memory Requests  Memory Limits
  ------------  ----------  ---------------  -------------
  810m (40%)    0 (0%)      110Mi (5%)       170Mi (8%)
Events:
  Type    Reason                   Age              From                         Message
  ----    ------                   ----             ----                         -------
  Normal  NodeHasSufficientDisk    9m (x8 over 9m)  kubelet, docker-for-desktop  Node docker-for-desktop status is now: NodeHasSufficientDisk
  Normal  NodeHasSufficientMemory  9m (x8 over 9m)  kubelet, docker-for-desktop  Node docker-for-desktop status is now: NodeHasSufficientMemory
  Normal  NodeHasNoDiskPressure    9m (x7 over 9m)  kubelet, docker-for-desktop  Node docker-for-desktop status is now: NodeHasNoDiskPressure
  Normal  Starting                 6m               kubelet, docker-for-desktop  Starting kubelet.
  Normal  NodeAllocatableEnforced  6m               kubelet, docker-for-desktop  Updated Node Allocatable limit across pods
  Normal  NodeHasSufficientDisk    5m (x8 over 6m)  kubelet, docker-for-desktop  Node docker-for-desktop status is now: NodeHasSufficientDisk
  Normal  NodeHasSufficientMemory  5m (x8 over 6m)  kubelet, docker-for-desktop  Node docker-for-desktop status is now: NodeHasSufficientMemory
  Normal  NodeHasNoDiskPressure    5m (x7 over 6m)  kubelet, docker-for-desktop  Node docker-for-desktop status is now: NodeHasNoDiskPressure

システムコンテナ

Kubernetes関連のコンテナはデフォルトでは見えないようになっています。

$ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

Preferenceで Show system containers にチェックを入れると、見れるようになります。

image.png

$ docker ps
CONTAINER ID        IMAGE                                                    COMMAND                  CREATED             STATUS              PORTS               NAMES
00d920237e91        docker/kube-compose-controller                           "/compose-controller…"   4 minutes ago       Up 3 minutes                            k8s_compose_compose-75f8bb4779-rd9b8_docker_0d27063d-f284-11e7-a992-025000000001_0
383d77fc9835        gcr.io/google_containers/k8s-dns-sidecar-amd64           "/sidecar --v=2 --lo…"   4 minutes ago       Up 3 minutes                            k8s_sidecar_kube-dns-545bc4bfd4-rvvzp_kube-system_eb5dbeb6-f283-11e7-a992-025000000001_0
33bc91c18665        gcr.io/google_containers/k8s-dns-dnsmasq-nanny-amd64     "/dnsmasq-nanny -v=2…"   4 minutes ago       Up 3 minutes                            k8s_dnsmasq_kube-dns-545bc4bfd4-rvvzp_kube-system_eb5dbeb6-f283-11e7-a992-025000000001_0
a07ccccbc715        gcr.io/google_containers/k8s-dns-kube-dns-amd64          "/kube-dns --domain=…"   4 minutes ago       Up 3 minutes                            k8s_kubedns_kube-dns-545bc4bfd4-rvvzp_kube-system_eb5dbeb6-f283-11e7-a992-025000000001_0
c62af488ecdb        gcr.io/google_containers/kube-proxy-amd64                "/usr/local/bin/kube…"   4 minutes ago       Up 3 minutes                            k8s_kube-proxy_kube-proxy-b94gv_kube-system_eb4494f6-f283-11e7-a992-025000000001_0
0d6870191555        gcr.io/google_containers/pause-amd64:3.0                 "/pause"                 4 minutes ago       Up 3 minutes                            k8s_POD_kube-dns-545bc4bfd4-rvvzp_kube-system_eb5dbeb6-f283-11e7-a992-025000000001_0
003ef58116b7        gcr.io/google_containers/pause-amd64:3.0                 "/pause"                 4 minutes ago       Up 3 minutes                            k8s_POD_kube-proxy-b94gv_kube-system_eb4494f6-f283-11e7-a992-025000000001_0
37c6084548b5        gcr.io/google_containers/pause-amd64:3.0                 "/pause"                 4 minutes ago       Up 3 minutes                            k8s_POD_compose-75f8bb4779-rd9b8_docker_0d27063d-f284-11e7-a992-025000000001_0
cd8c1ff65a12        gcr.io/google_containers/kube-controller-manager-amd64   "kube-controller-man…"   4 minutes ago       Up 3 minutes                            k8s_kube-controller-manager_kube-controller-manager-docker-for-desktop_kube-system_14053f30ffdac3d94dc69b1a16dc611d_0
8312db8077a8        gcr.io/google_containers/kube-scheduler-amd64            "kube-scheduler --ad…"   4 minutes ago       Up 3 minutes                            k8s_kube-scheduler_kube-scheduler-docker-for-desktop_kube-system_972d74c9fc2f4ebd8ab673058e386a65_0
78581567de01        gcr.io/google_containers/kube-apiserver-amd64            "kube-apiserver --ad…"   4 minutes ago       Up 3 minutes                            k8s_kube-apiserver_kube-apiserver-docker-for-desktop_kube-system_16875061c80d82c0825badac9afb1ff5_0
c2522304db1a        gcr.io/google_containers/etcd-amd64                      "etcd --advertise-cl…"   4 minutes ago       Up 3 minutes                            k8s_etcd_etcd-docker-for-desktop_kube-system_56a21c0a5f545c0cca5388c457bb1b3b_0
cffe2403d4f6        gcr.io/google_containers/pause-amd64:3.0                 "/pause"                 4 minutes ago       Up 3 minutes                            k8s_POD_kube-scheduler-docker-for-desktop_kube-system_972d74c9fc2f4ebd8ab673058e386a65_0
70a196659b1f        gcr.io/google_containers/pause-amd64:3.0                 "/pause"                 4 minutes ago       Up 3 minutes                            k8s_POD_kube-controller-manager-docker-for-desktop_kube-system_14053f30ffdac3d94dc69b1a16dc611d_0
1ff3169d6835        gcr.io/google_containers/pause-amd64:3.0                 "/pause"                 4 minutes ago       Up 3 minutes                            k8s_POD_kube-apiserver-docker-for-desktop_kube-system_16875061c80d82c0825badac9afb1ff5_0
ef1780261519        gcr.io/google_containers/pause-amd64:3.0                 "/pause"                 4 minutes ago       Up 3 minutes                            k8s_POD_etcd-docker-for-desktop_kube-system_56a21c0a5f545c0cca5388c457bb1b3b_0
taishin
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away