0
0

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 3 years have passed since last update.

CentOS7でkubernetes(Minikube)のインストールがうまくいかない (たった1日で基本が身につく!Docker/Kubernetes超入門 7章)

Posted at

はじめに

やはりインフラ関係は難しいですよね。
今回も「たった1日で基本が身につく!Docker/Kubernetes超入門」をやっていて本書通りに動かなかったため、解決策をまとめたいと思います。

問題

Ansibleを利用してMinikube環境を作成するときに以下のコマンドを実行します。

# ssh-cipy-id 10.149.245.121
# ansible-playbook -i 10.149.245.121, ./pb_centos7.yml

ansible-playbookをしたところ、install kubernetes if kubectl dose not existで以下のようなエラーとなります。

fatal: [10.149.245.121]: FAILED! => {"changed": true, "cmd": "/usr/local/bin/minikube --vm-driver=none start", "delta": "0:00:00.330972",  "stderr": "X Exiting due to GUEST_MDONNTRACK: Sorry, Kubernetes 1.21.1 reqyires conntrack to be installed in root's path", "stderr_lines": ["X Exiting due to GUEST_MISSING_EONNTRACK: Sorry, Kubernetes 1.21.2 reqyires conntrack tobe installed in root's path"], "stdout": "*minikube v1.22.0 in Centos 7.7 1900\n* Using the none driver based on user configuration", "stdout_lines": ["* minikube v1.22.0 on Centos7.7.1900", "* Using the none driver based on user configuration"}}

これは一部個所を変えています(ipなど)

解決方法

以下の2つの記事を参考に修正を行ったところインストールができるようになりました。

centos8でminikubeインストールでエラー
vagrantのLinuxでminikubeを動かしたい

まずは、1つ目の記事を参考に修正していきます。注意としては記事ではCentoOS8でやっているので、本に合わせてCentOS7でやっていきます。

まずは以下のコマンドを入力

# SELinux無効化
setenforce 0

# swap無効化
swapoff -a

そのあと、pb_centos7.ymlを以下の点を修正します。
・Dockerのバージョン下げ(minikubeが最新版Docker非対応のため。
・kubectlのバージョン変更
・client crtのパス変更

また記事はCentOS8なので、DockerのダウングレードはCentOS7に対応したものに変更しています。
このファイルを/chap7/ansible/minikube/のなかで実行します。ディレクトリをさらに深いところで行ったところCopy shell scripでエラーになりました。

pb_centos7.yml
- hosts: all
  remote_user: root
  tasks:
 
    - name: Disable firewalld
      systemd:
        name: firewalld
        state: stopped
        enabled: false
 
    - name: Change sshd config
      replace:
        dest: '/etc/ssh/sshd_config'
        regexp: '#MaxSessions 10'
        replace: 'MaxSessions 100'
      register: sshd_config
 
    - name: Restart sshd when config changed
      systemd:
        name: sshd
        state: restarted
        daemon_reload: yes
        enabled: yes
      when: sshd_config.changed
 
    - name: Copy ssh public key
      copy:
        src: ./id_rsa.pub
        dest: /root/.ssh/id_rsa.pub
        mode: 0644
 
    - name: Copy ssh private key
      copy:
        src: ./id_rsa
        dest: /root/.ssh/id_rsa
        mode: 0600
 
    - name: Copy shell script
      copy:
        src: ./set_secure_context.sh
        dest: /root/set_secure_context.sh
        mode: 0755
 
    - name: Copy shell script
      copy:
        src: ./set_secure_context.sh
        dest: /root/set_secure_context.sh
        mode: 0755
 
    - name: Add authorized key
      authorized_key:
        user: root
        state: present
        key: "{{ lookup('file', './id_rsa.pub') }}"
 
    - name: Install tools
      yum:
        name: "yum-utils,device-mapper-persistent-data,lvm2,zip,unzip"
        state: latest
 
    - name: Add Docker repo
      get_url:
        url: https://download.docker.com/linux/centos/docker-ce.repo
        dest: /etc/yum.repos.d/docer-ce.repo
 
    - name: Enable Docker Stable repo
      ini_file:
        dest: /etc/yum.repos.d/docer-ce.repo
        section: "docker-ce-stable"
        option: enabled
        value: "1"
 
    - name: Install docker
      yum:
        name: "docker-ce,docker-ce-cli,containerd.io"
        state: latest
 
    - name: Downgrade docker
      yum:
        name: "docker-ce-19.03.15-3.el8"
        allow_downgrade: yes
 
    - name: Download Docker Compose
      get_url: 
        url: https://github.com/docker/compose/releases/download/1.24.1/docker-compose-Linux-x86_64
        dest: /usr/local/bin/docker-compose
        mode: 0511
        
    - name: Start/Enable docker
      systemd:
        name: docker
        state: started
        daemon_reload: no
        enabled: yes
 
    - name: Download Minikube
      get_url: 
        url: https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
        dest: /usr/local/bin/minikube
        mode: 0511
 
    - name: Update kernel settings
      sysctl:
        name: net.bridge.bridge-nf-call-iptables
        value: "1"
        sysctl_set: yes
        state: present
        reload: yes
 
    - name: Check whether kubectl exist or not
      stat: path=/usr/local/bin/kubectl
      register: result1
 
    - name: Install Kubernetes if kubectl does not exist
      when: not result1.stat.exists
      shell: /usr/local/bin/minikube --vm-driver=none start
 
    - name: Download kubectl
      get_url: 
        url: https://storage.googleapis.com/kubernetes-release/release/v1.17.0/bin/linux/amd64/kubectl
        dest: /usr/local/bin/kubectl
        mode: 0511
 
    - name: Check whether kube-config.zip exit or not
      stat: path=/root/kube-config.zip
      register: result2
 
    - name: Generate kube-config if kube-config.zip does not exist
      when: not result2.stat.exists
      shell: /usr/local/bin/kubectl config view --raw > /root/config
 
    - name: Copy ca.* and client.* to /root/
      when: not result2.stat.exists
      shell: cp /root/.minikube/ca.* /root/; cp /root/.minikube/profiles/minikube/client.* /root/
 
    - name: Make kube-config.zip
      archive:
        path:
          - /root/config
          - /root/set_secure_context.sh
          - /root/set_insecure_context.sh
          - /root/ca.key
          - /root/ca.crt
          - /root/client.key
          - /root/client.crt
        dest: /root/kube-config.zip
        format: zip

ファイルの修正を行ったら、MinikubeをインストールするサーバーにSSH接続します
そのあと、conntrack_toolsをインストールします。

$ ssh root@10.149.245.121
$ yum install -y conntrack_tools
$ conntrack --version # (表示されればOK)
$ exit

これでインストールの準備ができました。

$ ansible-playbook -i 10.149.245.121
$ ssh root@10.149.245.121
$ kubectl get nodes # (表示されればOK)

これでうまくいきました。バージョン問題などがやはり本では影響してしまいます。
動いて良かったです。

おわりに

初心者には絶対にやりきれない本で確定です。
まだ先があるので、つまづいてしまわないか不安です。

参考

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?