※当サイトの記事には、広告・プロモーションが含まれます。

Vagrantで仮想マシンを構築後にAnsibleでKubernetes環境を構築してみる

gigazine.net

Microsoftが提供するWindows 10のメインストリームサポートは2025年10月14日(火)に終了します。サポート終了に納得のいかないユーザーの1人が、Microsoftを訴えました。

アメリカ人がWindows 10の提供中止を理由にMicrosoftを訴え無償延長サポートを要求 - GIGAZINE

⇧ 素晴らしい。流石は「訴訟大国」と呼ばれる「アメリカ」ですな。

そもそも、

gigazine.net

Microsoftが開発するOS「Windows」は、1985年に誕生したWindows 1.0からスタートして2012年にWindows 8が登場するまでたくさんのバージョン改訂を行い、それに伴ってOSとしての機能も大きく変化させてきました。そんなWindowsシリーズの最新バージョンとなるのが「Windows 10」ですが、Microsoftのジェリー・ニクソン氏が「Windows 10はWindowsの最後のバージョンとなる」と発言して話題になっています。

「Windows 10がWindowsの最後のバージョンになる」とMicrosoftが明言 - GIGAZINE

Microsoftで開発部門に属するジェリー・ニクソン氏は、アメリカ・シカゴで開催されたMicrosoft Igniteというイベントの中で、Windows 10がデスクトップソフトウェアの「最後のバージョンになる」と発言しています。

「Windows 10がWindowsの最後のバージョンになる」とMicrosoftが明言 - GIGAZINE

さらに、Microsoftも「Windowsは新しいイノベーションとアップデートを継続して提供していく」と声明を出しており、今後は独立した新しいバージョンを提供していくのではなく、既にリリースされているWindowsを数ヶ月ごとあるいは1年ごとに「大幅アップデート」していくことになるとコメント。

「Windows 10がWindowsの最後のバージョンになる」とMicrosoftが明言 - GIGAZINE

⇧ 10年前に、「Microsoft」が「Windows 10」が最後のバージョンになるって言ってたものな。

「Microsoft」に責任を取ってもらう必要がありますな。

本当に大企業だからといって、ユーザーを蔑ろにするのも大概にして欲しいですな...

VagrantでKubernetes環境を構築する手順が更新されていない...

公式のブログで、

kubernetes.io

⇧「Vagrant」を利用した「Kubernetes」環境の構築方法が紹介されているのだが、2019年の状態で更新されていない...

そもそも、手順が不足しているようで、

qiita.com

⇧ 上記サイト様にあるように「/etc/containerd/config.toml」に設定を追記したり、「Calico」の設定ファイルの修正などする必要があるようなのだが、公式の手順では何の説明も無いという...

あと、公式の手順は「Ansible」の「インベントリ」の設定とかも無く「localhost」で済ませているあたり、やる気を感じられない...

 

今は、2025年なのだが、

kubernetes.io

⇧ 上記の情報によると、「Linux ディストリビューション」の「パッケージ」の内、「Kubernetes」に関するものを管理している「リポジトリ」も変更されたようだ...

2025年8月13日(水)時点の最新の「Kubernetes」のバージョンは、「1.33」になるようだ。

kubernetes.io

ただ、

kubernetes.io

⇧ 上記のスケジュール通りに進めば、2025年8月末に「1.34」がリリースされるようだ...

例の如く、実用に耐え得る「Kubernetes」環境の構築に必要な情報が非常に分かり辛いのだが、

■containerd.io

github.com

■calico

archive-os-3-27.netlify.app

⇧ 上記の情報も変更されているので手順に反映する必要があると思われる。

Ansibleのインストール手順が不明瞭...

そして、

docs.ansible.com

galaxy.ansible.com

⇧ 上記の「Ansible」の「モジュール」もインストールする必要があるようだ。

ちなみに、「AlmaLinux」のバージョン10.x系の特有の問題なのか、「ansible」はインストールできず、「ansible-core」をインストールするしかないっぽい...

ただ、

ts0818.hatenablog.com

⇧ 上記の記事で触れたのだが、自分の環境では、「Almalinux 10」環境だと「命令セットアーキテクチャ(ISA:Instruction Set Architecture)」のエラーが出てしまうため、「Almalinux 9」を利用することにしたのだが、「Linux ディストリビューション」の「パッケージ管理ツール」所謂「dnf」コマンドでインストールできる「Ansible」のバージョンが古くなってしまうので、利用可能な最新のバージョンの「Python」をインストールして、「pip」もインストールして「Ansible」をインストールする形になると思われる。

Vagrantで仮想マシンを構築後にAnsibleでKubernetesを構築してみる

「仮想化ソフトウェア」としては、

⇧ 上記を利用していきます。

手順としては、

  1. Vagrantで仮想マシンを構築する
  2. 仮想マシンにSSHログインしAnsibleを実行する

の2段構えとなっている。

本来であれば、「Vagrant」で全て完結させたかったのだが、

ts0818.hatenablog.com

⇧ 上記の記事の時に、「Ansible」が「Linux」環境でしか動作しないことが分かったのと、「Vagrant」がタスクを分割できない仕様ということが分かったのと、吾輩の「ホスト」側の「PC」のスペックの問題もあり、「Vagrant」で全て実現するのは断念した...

イメージ的には、

⇧ 上図の仮想マシンを4台構築後に、「Ansible」のインストールされたマシンにSSHログインして「ansible-playbook」コマンドを実行して、「Kubernetes」環境を構築していく感じになる。

■ホスト側で用意するファイル群

D:\work-soft\vagrant\vagrant_up_kubernetes
│  Vagrantfile
│
└─vms
    └─ansible-controller
        └─scripts
            │  setup.sh
            │
            └─ansible
                │  master-playbook.yml
                │  node-playbook.yml
                │
                ├─files
                │      ready_ipv4_packet.sh
                │
                └─inventory
                        inventory.ini

で、各々のファイルの中身は以下のような感じになった。

■D:\work-soft\vagrant\vagrant_up_kubernetes\vms\ansible-controller\scripts\setup.sh

#!/bin/bash

sudo dnf -y update
sudo dnf install -y epel-release
# sudo dnf config-manager --set-enabled crb
# sudo dnf install -y ansible

# sshpassのインストール
sudo dnf install -y sshpass

### Pythonのバージョンアップ ###
# システムのデフォルトのpython3
SYSTEM_INSATLLED_DEFAULT_PYTHON=$(sudo ls /usr/bin | grep -oE '^python3\.[0-9]+' | sort -V | uniq | head -1)

# インストール可能な最新のバージョンのPythonをインストールする
AVAILABLE_INSTALL_LATEST_PYTHON=$(dnf list --available | grep -oE '^python3\.[0-9]+' | sort -V | uniq | tail -1)
sudo dnf install -y "${AVAILABLE_INSTALL_LATEST_PYTHON}"

# Pythonの切り替え
sudo alternatives --install /usr/bin/python3 python3 /usr/bin/"${SYSTEM_INSATLLED_DEFAULT_PYTHON}" 10
sudo alternatives --install /usr/bin/python3 python3 /usr/bin/"${AVAILABLE_INSTALL_LATEST_PYTHON}" 20

# Pythonが切り替わったか確認
echo "Current python version"
python3 -V

### Ansibleのインストール ###
# https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html
# pipのインストール
sudo curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3 get-pip.py --user

# Ansibleのインストール
python3 -m pip install --user ansible

# Ansibleのバージョン確認
ansible --version

# Ansibleのモジュール確認
ansible-galaxy collection list
    

■D:\work-soft\vagrant\vagrant_up_kubernetes\vms\ansible-controller\scripts\ansible\inventory\inventory.ini

[masters]
master ansible_host=192.168.50.10 node_ip=192.168.50.10
[workers]
worker1 ansible_host=192.168.50.11 node_ip=192.168.50.11
worker2 ansible_host=192.168.50.12 node_ip=192.168.50.12
[all:vars]
ansible_user=vagrant
ansible_ssh_pass=vagrant
ansible_sudo_pass=vagrant
ansible_ssh_common_args='-o StrictHostKeyChecking=no'
    

■D:\work-soft\vagrant\vagrant_up_kubernetes\vms\ansible-controller\scripts\ansible\files\ready_ipv4_packet.sh

#!/bin/bash

cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
overlay
br_netfilter
EOF

sudo modprobe overlay
sudo modprobe br_netfilter

# この構成に必要なカーネルパラメーター、再起動しても値は永続します
cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-iptables  = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.ipv4.ip_forward                 = 1
EOF

# 再起動せずにカーネルパラメーターを適用
sudo sysctl --system

lsmod | grep br_netfilter
lsmod | grep overlay

sysctl net.bridge.bridge-nf-call-iptables net.bridge.bridge-nf-call-ip6tables net.ipv4.ip_forward
    

■D:\work-soft\vagrant\vagrant_up_kubernetes\vms\ansible-controller\scripts\ansible\master-playbook.yml

---
# Step 2: Create an Ansible playbook for Kubernetes master.
- hosts: all
  become: true
  tasks:

  ## SELinuxの設定
  - name: Set SELinux to permissive mode temporarily
    ansible.builtin.command: setenforce 0

  - name: Ensure SELinux is in permissive mode permanently
    ansible.builtin.lineinfile:
      path: /etc/selinux/config
      regexp: '^SELINUX='
      line: 'SELINUX=permissive'
      state: present
  
  ## ローカル(Ansibleがインストールされているマシン)からリモートにファイルコピー
  - name: Copy scriptfile from local to remote
    ansible.builtin.copy:
      remote_src: false
      src: "/tmp/ansible-controller/scripts/ansible/files/ready_ipv4_packet.sh"
      dest: "/home/vagrant/ready_ipv4_packet.sh"
      mode: '0755'

  ## Enable IPv4 packet forwarding
  - name: Enable IPv4 packet forwarding
    ansible.builtin.shell:
      /home/vagrant/ready_ipv4_packet.sh
    register: result_script
  
  ## Result Enable IPv4 packet forwarding
  - name: Result Enable IPv4 packet forwarding
    ansible.builtin.debug:
      msg: "Result Enable IPv4 packet forwarding: {{ result_script }}"

  ## Step 2.1: Install Docker and its dependent components.
  - name: Install required dependencies for Docker
    ansible.builtin.dnf:
      name: "{{ packages }}"
      state: present
      update_cache: yes
    vars:
      packages:
        - yum-utils
        - device-mapper-persistent-data
        - lvm2
        - curl

  - name: Add Docker repository
    ansible.builtin.get_url:
      url: https://download.docker.com/linux/centos/docker-ce.repo
      dest: /etc/yum.repos.d/docker-ce.repo
      mode: '0644'
    register: docker_repo
    
  - name: Display error message if Docker repository download fails
    ansible.builtin.debug:
      msg: "Result download Docker repository file: {{ docker_repo }}"

  - name: Install Docker and its dependencies
    ansible.builtin.dnf:
      name: "{{ packages }}"
      state: present
      update_cache: yes
    vars:
      packages:
        - docker-ce
        - docker-ce-cli
        - containerd.io
    notify:
      - docker status

  - name: Add vagrant user to docker group
    ansible.builtin.user:
      name: vagrant
      group: docker
  
  - name: Containerd default config
    ansible.builtin.shell: |
      containerd config default | sudo tee /etc/containerd/config.toml

  - name: Set SystemdCgroup=true in specific containerd config section
    ansible.builtin.shell:
      sudo sed -i -e 's/SystemdCgroup = false/SystemdCgroup = true/g' /etc/containerd/config.toml

#  - name: Copy file from local
#    ansible.builtin.copy:
#      remote_src: false
#      src: /tmp/ansible-controller/scripts/ansible/files/containerd/config.toml
#      dest: /etc/containerd/config.toml
#      backup: true

  - name: Containerd service start
    ansible.builtin.service:
      name: containerd
      state: restarted
      enabled: yes

  - name: Docker service start
    ansible.builtin.service:
      name: docker
      state: started
      enabled: yes

  ## Step 2.2: Kubelet will not start if the system has swap enabled, so we are disabling swap using the below code.
  - name: Remove swapfile from /etc/fstab
    ansible.posix.mount:
      name: "{{ item }}"
      fstype: swap
      state: absent
    with_items:
      - swap
      - none

  - name: Disable swap
    ansible.builtin.command: swapoff -a
    when: ansible_swaptotal_mb > 0

  ## Step 2.3: Installing kubelet, kubeadm and kubectl using the below code.
#  - name: Add Kubernetes repository
#    get_url:
#      url: https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64.repo
#      dest: /etc/yum.repos.d/kubernetes.repo
  - name: Add Kubernetes repo
    ansible.builtin.yum_repository:
      name: kubernetes
      description: Kubernetes
      baseurl: https://pkgs.k8s.io/core:/stable:/v1.33/rpm/
      enabled: 1
      gpgcheck: 1
      gpgkey: https://pkgs.k8s.io/core:/stable:/v1.33/rpm/repodata/repomd.xml.key
      exclude: kubelet,kubeadm,kubectl,cri-tools,kubernetes-cni
      state: present

  - name: Install Kubernetes binaries
    ansible.builtin.dnf:
      name: "{{ packages }}"
      state: present
      update_cache: yes
      disable_excludes: all
    vars:
      packages:
        - kubelet
        - kubeadm
        - kubectl

  - name: Configure node ip
    ansible.builtin.lineinfile:
      path: /etc/sysconfig/kubelet
#      path: /etc/default/kubelet
      line: KUBELET_EXTRA_ARGS=--node-ip={{ node_ip }}

  - name: Restart kubelet
    ansible.builtin.service:
      name: kubelet
      daemon_reload: true
      state: restarted
      enabled: true

  - name: Task only master node
    when: "'masters' in group_names"
    block:
      ## Step 2.4: Initialize the Kubernetes cluster with kubeadm using the below code (applicable only on master node).
      - name: Initialize the Kubernetes cluster using kubeadm
        ansible.builtin.command: kubeadm init --apiserver-advertise-address="192.168.50.10" --apiserver-cert-extra-sans="192.168.50.10" --node-name k8s-master --pod-network-cidr=172.16.0.0/16

      - name: Wait for Kubernetes API server to become available
        wait_for:
          host: 192.168.50.10
          port: 6443
          delay: 5
          timeout: 180
          state: started
#        register: api_server_check
#        failed_when: api_server_check.failed
#
#      - name: Show result of API server check
#        ansible.builtin.debug:
#          msg: >
#            Kubernetes API server is {{
#            'available' if not api_server_check.failed else 'NOT available'
#            }} at port 6443.

      ## Step 2.5: Setup the kube config file for the vagrant user to access the Kubernetes cluster using the below code.
      - name: Setup kubeconfig for vagrant user
        ansible.builtin.command: "{{ item }}"
        with_items:
         - mkdir -p /home/vagrant/.kube
         - cp -i /etc/kubernetes/admin.conf /home/vagrant/.kube/config
         - chown vagrant:vagrant /home/vagrant/.kube/config

      ## Step 2.6: Setup the container networking provider and the network policy engine using the below code.
      - name: Block Ready Calico
        when: "'masters' in group_names"
        block:
          ### 1. Install the Tigera Operator and custom resource definitions.
          - name: Install the Tigera Operator and custom resource definitions.
#            command: kubectl create -f https://docs.projectcalico.org/v3.4/getting-started/kubernetes/installation/hosted/calico.yaml
            ansible.builtin.shell: |
              curl -OL https://raw.githubusercontent.com/projectcalico/calico/v3.30.2/manifests/operator-crds.yaml
              kubectl create -f operator-crds.yaml
              curl -OL https://raw.githubusercontent.com/projectcalico/calico/v3.30.2/manifests/tigera-operator.yaml
              kubectl create -f tigera-operator.yaml
          
          ### 2. Download the custom resources necessary to configure Calico.
          - name: Download the custom resources necessary to configure Calico.
            ansible.builtin.shell:
              curl https://raw.githubusercontent.com/projectcalico/calico/v3.30.2/manifests/custom-resources.yaml -O
          
          ### CalicoのPodネットワークの修正
          - name: Modify Calico Pod network
            ansible.builtin.shell: |
              sudo sed -i -e 's#cidr: 192.168.0.0/16#cidr: 172.16.0.0/16#g' /home/vagrant/custom-resources.yaml
          
          ### 3. Create the manifest to install Calico.
          - name: Create the manifest to install Calico.
            ansible.builtin.shell:
              kubectl create -f /home/vagrant/custom-resources.yaml
          
          ### 4. Verify Calico installation in your cluster.
          - name: Verify Calico installation in your cluster.
            ansible.builtin.shell:
              #watch kubectl get pods -n calico-system
              kubectl get pods -A
        become: false

      ## Step 2.7: Generate kube join command for joining the node to the Kubernetes cluster and store the command in the file named join-command.
      - name: Generate join command
        ansible.builtin.command: kubeadm token create --print-join-command
        register: join_command

      - name: Copy join command to local file
#        local_action: 
        ansible.builtin.copy:
          content: "{{ join_command.stdout_lines[0] }}"
          dest: "./join-command"
        delegate_to: localhost 

  ## Step 2.8: Setup a handler for checking Docker daemon using the below code.
  handlers:
    - name: docker status
      ansible.builtin.service: name=docker state=started enabled=true

■D:\work-soft\vagrant\vagrant_up_kubernetes\vms\ansible-controller\scripts\ansible\node-playbook.yml

# Step 3: Create the Ansible playbook for Kubernetes node.
- hosts: workers
  become: true
  tasks:
  ## Step 3.1: Start adding the code from Steps 2.1 till 2.3.
  ## Step 2.1: Install Docker and its dependent components.
  ### task taht 2.1 till 2.3 is already done master-playbook.yml 
#  - name: Install required dependencies for Docker
#    dnf:
#      name: "{{ packages }}"
#      state: present
#      update_cache: yes
#    vars:
#      packages:
#        - yum-utils
#        - device-mapper-persistent-data
#        - lvm2
#        - curl
#
#  - name: Add Docker repository
#    get_url:
#      url: https://download.docker.com/linux/centos/docker-ce.repo
#      dest: /etc/yum.repos.d/docker-ce.repo
#
#  - name: Install Docker and its dependencies
#    dnf:
#      name: "{{ packages }}"
#      state: present
#      update_cache: yes
#    vars:
#      packages:
#        - docker-ce
#        - docker-ce-cli
#        - containerd.io
#    notify:
#      - docker status
#
#  - name: Add vagrant user to docker group
#    user:
#      name: vagrant
#      group: docker
#
# ## Step 2.2: Kubelet will not start if the system has swap enabled, so we are disabling swap using the below code.
#  - name: Remove swapfile from /etc/fstab
#    mount:
#      name: "{{ item }}"
#      fstype: swap
#      state: absent
#    with_items:
#      - swap
#      - none
#
#  - name: Disable swap
#    command: swapoff -a
#    when: ansible_swaptotal_mb > 0
#
# ## Step 2.3: Installing kubelet, kubeadm and kubectl using the below code.
#  - name: Add Kubernetes repository
#    get_url:
#      url: https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64.repo
#      dest: /etc/yum.repos.d/kubernetes.repo
#
#  - name: Install Kubernetes binaries
#    dnf:
#      name: "{{ packages }}"
#      state: present
#      update_cache: yes
#    vars:
#      packages:
#        - kubelet
#        - kubeadm
#        - kubectl
#
#  - name: Configure node ip
#    lineinfile:
#      path: /etc/sysconfig/kubelet
#      line: KUBELET_EXTRA_ARGS=--node-ip={{ node_ip }}
#
#  - name: Restart kubelet
#    service:
#      name: kubelet
#      state: restarted
#      enabled: true

  ## Step 3.2: Join the nodes to the Kubernetes cluster using below code.
  - name: Copy the join command to server location
    ansible.builtin.copy:
      remote_src: false
      src: "./join-command"
      dest: "/tmp/join-command.sh"
      mode: '0777'

  - name: Join the node to cluster
    ansible.builtin.shell: 
      sh /tmp/join-command.sh
    register: result_join_cluster
  
  - name: Result Join the node to cluster
    ansible.builtin.debug:
      msg: "Result Join the node to cluster: {{ result_join_cluster }}"

  ## Step 3.3: Add the code from step 2.7 to finish this playbook.
  ## Step 2.8: Setup a handler for checking Docker daemon using the below code.
  handlers:
    - name: docker status
      ansible.builtin.service: 
        name: docker
        state: started
        enabled: true

■D:\work-soft\vagrant\vagrant_up_kubernetes\Vagrantfile

# https://portal.cloud.hashicorp.com/vagrant/discover/almalinux/10-x86_64_v2
# IMAGE_NAME = "almalinux/10-x86_64_v2"
# IMAGE_VESION = "10.0.20250529"

# https://portal.cloud.hashicorp.com/vagrant/discover/almalinux/10
# IMAGE_NAME = "almalinux/10"
# IMAGE_VESION = "10.0.20250529"

# https://portal.cloud.hashicorp.com/vagrant/discover/almalinux/9
IMAGE_NAME = "almalinux/9"
IMAGE_VESION = "9.6.20250522"

N = 2

Vagrant.configure("2") do |config|
    config.ssh.insert_key = false

    config.vm.provider "virtualbox" do |v|
        v.memory = 1024
        v.cpus = 1
    end

    # Ansible実行用の作業用仮想マシン
    config.vm.define "ansible-controller" do |ansible|
        # Almalinux 9.6 のVagrantのBoxだとメモリ1GBではOOM killerが発生したので
        ansible.vm.provider "virtualbox" do |v|
            v.memory = 2048
        end
        ansible.vm.box = IMAGE_NAME
        ansible.vm.box_version = IMAGE_VESION
        # ホストオンリーアダプター
        ansible.vm.network "private_network", ip: "192.168.56.101"
        # 内部ネットワーク
        ansible.vm.network "private_network", ip: "192.168.50.101", virtualbox__intnet: true
        ansible.vm.hostname = "ansible-controller"
        
        # ansibleのインストールに必要なスクリプトファイルをコピー
        ansible.vm.provision "file", source: "vms/ansible-controller/scripts/setup.sh", destination: "/tmp/ansible-controller/scripts/setup.sh"
        # ansibleの実行に必要なファイルをコピー
        ansible.vm.provision "file", source: "vms/ansible-controller/scripts/ansible", destination: "/tmp/ansible-controller/scripts/ansible"
#        ansible.vm.provision "shell", privileged: true, inline: <<-SHELL
        ansible.vm.provision "shell", privileged: false, inline: <<-SHELL
          chmod +x /tmp/ansible-controller/scripts/setup.sh
          chmod -R +x /tmp/ansible-controller/scripts/ansible
          # スクリプトファイルの実行
          /tmp/ansible-controller/scripts/setup.sh
        SHELL
    end

    # Kubernetesクラスターのmaster node用の仮想マシン
    config.vm.define "k8s-master" do |master|
        master.vm.provider "virtualbox" do |v|
            v.memory = 2048
            v.cpus = 2
        end
        master.vm.box = IMAGE_NAME
        master.vm.box_version = IMAGE_VESION
        # ホストオンリーアダプター
        master.vm.network "private_network", ip: "192.168.56.10"
        # 内部ネットワーク
        master.vm.network "private_network", ip: "192.168.50.10", virtualbox__intnet: true
        master.vm.hostname = "k8s-master"
#        master.vm.provision "ansible" do |ansible|
#            ansible.playbook = "kubernetes-setup/master-playbook.yml"
#            ansible.extra_vars = {
#                node_ip: "192.168.50.10",
#            }
#        end
        master.vm.provision "shell", privileged: true, inline: <<-SHELL
          sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bk
          sudo sed -i 's/^#\?PasswordAuthentication .*/PasswordAuthentication yes/' /etc/ssh/sshd_config
          sudo sed -i 's/^#\?ChallengeResponseAuthentication .*/ChallengeResponseAuthentication yes/' /etc/ssh/sshd_config
        SHELL
    end

    # Kubernetesクラスターのworker node用の仮想マシン
    (1..N).each do |i|
        config.vm.define "node-#{i}" do |node|
            node.vm.box = IMAGE_NAME
            node.vm.box_version = IMAGE_VESION
            # 内部ネットワーク
            node.vm.network "private_network", ip: "192.168.50.#{i + 10}", virtualbox__intnet: true
            node.vm.hostname = "node-#{i}"
#            node.vm.provision "ansible" do |ansible|
#                ansible.playbook = "kubernetes-setup/node-playbook.yml"
#                ansible.extra_vars = {
#                    node_ip: "192.168.50.#{i + 10}",
#                }
#            end
            node.vm.provision "shell", privileged: true, inline: <<-SHELL
              sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bk
              sudo sed -i 's/^#\?PasswordAuthentication .*/PasswordAuthentication yes/' /etc/ssh/sshd_config
              sudo sed -i 's/^#\?ChallengeResponseAuthentication .*/ChallengeResponseAuthentication yes/' /etc/ssh/sshd_config
            SHELL

        end
    end
end    

⇧ で、「Vagrantfile」の配置されているディレクトリに移動し、

vagrant up

「仮想マシン」が構築できたら、「Ansible」がインストールされているマシンにSSHログインする。

■「Ansible」がインストールされているマシンにSSHログインする

vagrant ssh k8s-master   

で、「Ansible」の「Playbook」の「YAML」ファイルが配置されているディレクトリに移動し、「Playbook」の実行。

■ディレクトリ移動

cd /tmp/ansible-controller/scripts/ansible; pwd    

■Playbookの実行(Kubernetesクラスターを構築する)

ansible-playbook -i inventory/inventory.ini master-playbook.yml   

もう1つの「Playbook」を実行して、「Worker Node」を「Master Node」に追加する。

■Playbookの実行(Workerノードをkubernetesクラスタへ参加させる)

ansible-playbook -i inventory/inventory.ini node-playbook.yml   

Podが立ち上がるのも遅い...

と言うか、マシンのスペックの問題なのか、普通にPodが落ちてるな...

漸く全てのPodがrunning状態になったのだが、これ、「アプリケーション」の「Pod」追加するリソースの余裕が無い気がするのだが...



ちなみに、

■Playbookの実行(Kubernetesクラスターを構築する)で出るエラー

D:\work-soft\vagrant\vagrant_up_kubernetes>vagrant ssh k8s-master
Last login: Wed Aug 13 10:28:14 2025 from 192.168.50.101
[vagrant@k8s-master ~]$ sudo cat /var/log/>
May 22 13:10:15 vbox python3[46629]: ansible-ansible.legacy.command Invoked with _raw_params=truncate -s 0 /var/log/> _uses_shell=False expand_argument_vars=True stdin_add_newline=True strip_empty_ends=True argv=None chdir=None executable=None creates=None removes=None stdin=None

...省略

Aug 13 10:31:47 k8s-master systemd[1]: Starting Hostname Service...
Aug 13 10:31:47 k8s-master containerd[8870]: time="2025-08-13T10:31:47.587574702Z" level=info msg="RunPodSandbox for &PodSandboxMetadata{Name:kube-proxy-5zzsj,Uid:7d0d57d2-e936-4842-8759-f0d922ae09d6,Namespace:kube-system,Attempt:0,} returns sandbox id \"f1256be7d4749c6ed3b0c49db795120f0721211a2acc49fcc5fd2563edab7ddf\""
Aug 13 10:31:47 k8s-master systemd-udevd[11342]: Using default interface naming scheme 'rhel-9.0'.
Aug 13 10:31:47 k8s-master containerd[8870]: time="2025-08-13T10:31:47.614197976Z" level=info msg="CreateContainer within sandbox \"f1256be7d4749c6ed3b0c49db795120f0721211a2acc49fcc5fd2563edab7ddf\" for container &ContainerMetadata{Name:kube-proxy,Attempt:0,}"
Aug 13 10:31:47 k8s-master systemd[1]: Started Hostname Service.
Aug 13 10:31:47 k8s-master systemd[1]: Started Rule-based Manager for Device Events and Files.
Aug 13 10:31:47 k8s-master systemd[1]: var-lib-containerd-tmpmounts-containerd\x2dmount168866409.mount: Deactivated successfully.
Aug 13 10:31:47 k8s-master systemd[1]: var-lib-containerd-tmpmounts-containerd\x2dmount1981665484.mount: Deactivated successfully.
Aug 13 10:31:47 k8s-master containerd[8870]: time="2025-08-13T10:31:47.711659621Z" level=info msg="CreateContainer within sandbox \"f1256be7d4749c6ed3b0c49db795120f0721211a2acc49fcc5fd2563edab7ddf\" for &ContainerMetadata{Name:kube-proxy,Attempt:0,} returns container id \"202f711f6a71a0f4b3f6a62bb401c15151ba321c13e1f3852a780815663ec5d1\""
Aug 13 10:31:47 k8s-master containerd[8870]: time="2025-08-13T10:31:47.714301120Z" level=info msg="StartContainer for \"202f711f6a71a0f4b3f6a62bb401c15151ba321c13e1f3852a780815663ec5d1\""
Aug 13 10:31:47 k8s-master systemd[1]: Started libcontainer container 202f711f6a71a0f4b3f6a62bb401c15151ba321c13e1f3852a780815663ec5d1.
Aug 13 10:31:47 k8s-master containerd[8870]: time="2025-08-13T10:31:47.939910185Z" level=info msg="StartContainer for \"202f711f6a71a0f4b3f6a62bb401c15151ba321c13e1f3852a780815663ec5d1\" returns successfully"
Aug 13 10:31:48 k8s-master kubelet[11112]: I0813 10:31:48.098019   11112 pod_startup_latency_tracker.go:104] "Observed pod startup duration" pod="kube-system/kube-proxy-5zzsj" podStartSLOduration=213.098000933 podStartE2EDuration="3m33.098000933s" podCreationTimestamp="2025-08-13 10:28:15 +0000 UTC" firstStartedPulling="0001-01-01 00:00:00 +0000 UTC" lastFinishedPulling="0001-01-01 00:00:00 +0000 UTC" observedRunningTime="2025-08-13 10:31:48.096633946 +0000 UTC m=+215.456504957" watchObservedRunningTime="2025-08-13 10:31:48.098000933 +0000 UTC m=+215.457871945"
Aug 13 10:31:50 k8s-master kubelet[11112]: E0813 10:31:50.299749   11112 kubelet.go:3117] "Container runtime network not ready" networkReady="NetworkReady=false reason:NetworkPluginNotReady message:Network plugin returns error: cni plugin not initialized"
Aug 13 10:31:55 k8s-master kubelet[11112]: E0813 10:31:55.301398   11112 kubelet.go:3117] "Container runtime network not ready" networkReady="NetworkReady=false reason:NetworkPluginNotReady message:Network plugin returns error: cni plugin not initialized"

⇧ 上記のエラーが出るのは問題ないらしい。

と言うのも、「kubeadm init」の後述の手順で「CNI プラグイン」の1つである「Calico」をインストールすることになっているので。

正常に処理されてもエラーが出ると言うのは、公式のドキュメントに記載しておいて欲しいよね...

パソコンのスペックの問題なのか、「Ansible」の「Playbook」の実行が安定しない...

「冪等性」は夢のまた夢と言う感じか...

そして、悲報...

qiita.com

⇧ 上記サイト様の説明にあるように、「Kubernetes」環境の「切り戻し」の公式の手順についても、ファジーな状態のようだ...

「Kubernetes」環境を構築する公式の手順を整備して欲しいよね...

手軽に「学習」できるように「Kubernetes」環境構築の公式の手順は「MECE(Mutually Exclusive and Collectively Exhaustive)」な状態にして欲しい...

つまり、不特定の作業者が何度実行しても同じ環境構築が実現できる「冪等性」のある手順にして欲しいのよ...

環境構築の手順系については、「AI」も全く役に立たないからなぁ...

ちなみに、「Ansible」の「shell」モジュールで、

  1. ヒアドキュメント
  2. パイプ

の併用が機能しないというのも辛過ぎるんだが...

結局、「シェルスクリプトファイル」でごまかすしかないというね...

あと、「Ansible」は、

  1. ローカル
  2. リモート

のどちらで値を持っているのか混乱するのよね...

「Kubernetes」にしろ「Ansible」にしろ、いろいろと実現して欲しい「要件」が漏れているので、中途半端になっているのよね...

貴重な休日が潰れる割には、何も得るものが無いという不毛な時間を費やすことになって、本当に「Kubernetes」の「保守・運用」の「費用対効果」が割に合わない気がしますな...

そもそも、「Kubernetes」環境の構築って、「ソフトウェアエンジニア」の領域では無い気がするのだが、「Kubernetes」環境の構築が終わらないと「アプリケーションレイヤー」の作業に入れないですしな...

ストレスが蓄積するだけなのよね...

毎度モヤモヤ感が半端ない…

今回はこのへんで。