なになれ

IT系のことを記録していきます

AnsibleとVagrantでKubernetesをセットアップする

以下を試してみた内容です。 kubernetes.io

2019年9月25日現在、この内容を試すとうまく動作しない部分があるので、直しつつ進めました。
なお、ローカルのOSはmacOS 10.14.6になります。
以下、Stepごとに修正点を補記します。

Step 1: Creating a Vagrantfile

変更なし

Step 2.1: Install Docker and its dependent components.

変更なし

Step 2.2: Kubelet will not start if the system has swap enabled, so we are disabling swap using the below code.

変更なし

Step 2.3: Installing kubelet, kubeadm and kubectl using the below code.

変更なし

Step 2.3: Initialize the Kubernetes cluster with kubeadm using the below code (applicable only on master node).

kubeletの設定ファイルを作成する記述を追加

    - name: Configure node ip
      lineinfile:
        create: yes # <- 追記
        path: /etc/default/kubelet
        line: KUBELET_EXTRA_ARGS=--node-ip={{ node_ip }}

Step 2.4: Setup the kube config file for the vagrant user to access the Kubernetes cluster using the below code.

変更なし

Step 2.5: Setup the container networking provider and the network policy engine using the below code.

calicoのバージョンを最新にする

    - name: Install calico pod network
      become: false
      command: kubectl apply -f https://docs.projectcalico.org/v3.9/manifests/calico.yaml  # <- 変更

Step 2.6: Generate kube join command for joining the node to the Kubernetes cluster and store the command in the file named join-command.

join-commandのコピー時に非root権限で実施する

    - name: Copy join command to local file
      become: false
      local_action: copy content="{{ join_command.stdout_lines[0] }}" dest="./join-command"

Step 2.7: Setup a handler for checking Docker daemon using the below code.

変更なし

Step 3: Create the Ansible playbook for Kubernetes node.

変更なし

Step 3.1: Start adding the code from Steps 2.1 till 2.3.

変更なし

Step 3.2: Join the nodes to the Kubernetes cluster using below code.

変更なし

Step 3.3: Add the code from step 2.7 to finish this playbook.

変更なし

Step 4: Upon completing the Vagrantfile and playbooks follow the below steps.

変更なし

全内容

gist.github.com