はじめに
昨今話題のKubernetesについて学習をはじめました。
社内のセミナーでも良く説明があり、簡単な用語は幾度となく聞いた気がします。
しかし、技術者の端くれとしては実際に手を動かしてみないと腹落ちしないなと思っていました。
そこで、Minikube環境を用いて実際に体感してみることとしました。
当文書では、Kubernetesについて学んだあれこれを書きたいと思いつつ、まずは環境を用意するところまでのメモが中心になると思います。
関連記事
【Kubernetes入門】Minikube環境を立ち上げるためのVagrant学習
【Kubernetes入門】Minikube環境を立ち上げるためのAnsible学習
参考情報
Kubernetesの学習教材として、日本IBM高良さんの技術書『15Stepで習得 Dockerから入るKubernetes』(amazonリンク)を用いました。
まだ読み途中ですが、とても分厚く(笑)、とても内容が充実している良書です。
環境情報
VagrantのUbuntu上でMinikubeを動かします。PCはmacOSです。
といっても、これも高良さんが公開されているvagrant-minikubeを活用します。
ただし、せっかくのスタディーですので、このレポジトリの内容もしっかり抑えたいと思います。
さすがにVirtualBoxやVagrantなどのインストールは割愛します。
Vagrantのおさらい
vagrant-minikubeレポジトリがVagrantfileを適切に用意してくださっているのでvagrant up
コマンドだけで仮想マシン環境は用意されます。
しかし!これだけで終わっては学習の意味がないので、Vagrantfileを確認したいと思います。
Vagrant.configure("2") do |config|
config.vm.define 'minikube' do |machine|
machine.vm.box = "ubuntu/xenial64"
machine.vm.hostname = 'minikube'
machine.vm.network :private_network,ip: "172.16.10.10"
machine.vm.provider "virtualbox" do |vbox|
vbox.gui = false
vbox.cpus = 2
vbox.memory = 2048
end
machine.vm.provision "ansible_local" do |ansible|
ansible.playbook = "minikube.yml"
ansible.version = "latest"
ansible.verbose = false
ansible.install = true
ansible.limit = "minikube"
ansible.inventory_path = "hosts"
end
end
end
vm.define
複数台分の仮装マシン(Multi-Machine)を設定する場合に使います。
詳細はこちらのドキュメントを参照してください。
vm.box
仮想マシンのOSイメージを指定します。
ここではUbuntu16の64bit版ubuntu/xenial64
を指定しています。
boxはこちらから探すことができます。
vm.network
仮想マシンのネットワーク環境を設定します。
ここではprivate_network
が指定されているので、ホストOSからのみアクセス可能となります。
vm.provider "name of the provider"
仮想化ソフトウェアを指定し、仮想マシンのCPUやメモリサイズを指定します。
ここではVirtualBoxを指定し、各種設定を行っています。
vm.provision "name of the provisioner"
Provisionerを指定します。
詳細はこちらのドキュメントを参照していただきたいですが、簡単に言えばソフトウェアのインストールや初回セットアップなどを自動実行させるための設定です。
ここではansible_local
(Ansible Local)が使われています。
ansible_local
ではゲストOS側でAnsibleを起動することになります。
ansible.playbook
Ansible playbookのパスを指定します。playbookの中身はまた後ほど確認します。
ansible.version
ゲストOS側にインストールするAnsibleのバージョンを指定します。
ここではlatest
が指定されているため、最新バージョンがインストールされます。
ansible.verbose
Ansibleのverboseオプションを指定します。
デフォルトはfalse
ですが、詳細を出力したい場合にはtrue
(=v
),や-vvv
などを指定します。
ansible.limit
Vagrantfileのマシン名とansible.inventory_path
で指定したInventryfile内のマシン名を関連づけるためのマシン名などを指定します。
ansible.inventory_path
Ansible Inventryfileのパスを指定します。
今回のまとめ
ここまでMinikube環境を構築するためのVagrantfileについて確認してきました。
思わずVagrantfileのおさらいをしてしまったので、Minikube環境立ち上げに至っていませんが今回はここまでとします。
次はAnsibleのメインかな。。。
最後に、このVagrantfileをもとにvagrant up
をした際のログを添付しておきます。
参考にしてください。
作業ログ
$ vagrant up
Bringing machine 'minikube' up with 'virtualbox' provider...
==> minikube: Importing base box 'ubuntu/xenial64'...
==> minikube: Matching MAC address for NAT networking...
==> minikube: Checking if box 'ubuntu/xenial64' version '20200212.0.0' is up to date...
==> minikube: Setting the name of the VM: vagrant-minikube_minikube_1581896627682_21373
==> minikube: Clearing any previously set network interfaces...
==> minikube: Preparing network interfaces based on configuration...
minikube: Adapter 1: nat
minikube: Adapter 2: hostonly
==> minikube: Forwarding ports...
minikube: 22 (guest) => 2222 (host) (adapter 1)
==> minikube: Running 'pre-boot' VM customizations...
==> minikube: Booting VM...
==> minikube: Waiting for machine to boot. This may take a few minutes...
minikube: SSH address: 127.0.0.1:2222
minikube: SSH username: vagrant
minikube: SSH auth method: private key
minikube: Warning: Connection reset. Retrying...
minikube: Warning: Remote connection disconnect. Retrying...
minikube:
minikube: Vagrant insecure key detected. Vagrant will automatically replace
minikube: this with a newly generated keypair for better security.
minikube:
minikube: Inserting generated public key within guest...
minikube: Removing insecure key from the guest if it's present...
minikube: Key inserted! Disconnecting and reconnecting using new SSH key...
==> minikube: Machine booted and ready!
==> minikube: Checking for guest additions in VM...
minikube: The guest additions on this VM do not match the installed version of
minikube: VirtualBox! In most cases this is fine, but in rare cases it can
minikube: prevent things such as shared folders from working properly. If you see
minikube: shared folder errors, please make sure the guest additions within the
minikube: virtual machine match the version of VirtualBox you have installed on
minikube: your host and reload your VM.
minikube:
minikube: Guest Additions Version: 5.1.38
minikube: VirtualBox Version: 6.0
==> minikube: Setting hostname...
==> minikube: Configuring and enabling network interfaces...
==> minikube: Mounting shared folders...
minikube: /vagrant => /Users/shuari/git/takara9/vagrant-minikube
==> minikube: Running provisioner: ansible_local...
minikube: Installing Ansible...
Vagrant has automatically selected the compatibility mode '2.0'
according to the Ansible version installed (2.9.4).
Alternatively, the compatibility mode can be specified in your Vagrantfile:
https://www.vagrantup.com/docs/provisioning/ansible_common.html#compatibility_mode
minikube: Running ansible-playbook...
PLAY [minikube] ****************************************************************
TASK [Gathering Facts] *********************************************************
[DEPRECATION WARNING]: Distribution Ubuntu 16.04 on host minikube should use
/usr/bin/python3, but is using /usr/bin/python for backward compatibility with
prior Ansible releases. A future Ansible release will default to using the
discovered platform python for this host. See https://docs.ansible.com/ansible/
2.9/reference_appendices/interpreter_discovery.html for more information. This
feature will be removed in version 2.12. Deprecation warnings can be disabled
by setting deprecation_warnings=False in ansible.cfg.
ok: [minikube]
TASK [Add Docker GPG key] ******************************************************
changed: [minikube]
TASK [Add Docker APT repository] ***********************************************
changed: [minikube]
TASK [Install packages] ********************************************************
changed: [minikube]
TASK [Install Docker-CE] *******************************************************
changed: [minikube]
TASK [usermod -aG docker vagrant] **********************************************
changed: [minikube]
TASK [Set sysctl] **************************************************************
changed: [minikube]
[WARNING]: The value 1 (type int) in a string field was converted to u'1' (type
string). If this does not look like what you expect, quote the entire value to
ensure it does not change.
TASK [Add GlusterFS Repository] ************************************************
changed: [minikube]
TASK [Install GlusterFS] *******************************************************
changed: [minikube]
TASK [download] ****************************************************************
changed: [minikube]
TASK [download] ****************************************************************
changed: [minikube]
TASK [start Minikube temporary] ************************************************
changed: [minikube]
TASK [waiting] *****************************************************************
changed: [minikube]
TASK [stopping Minikube] *******************************************************
changed: [minikube]
TASK [waiting] *****************************************************************
changed: [minikube]
TASK [shell] *******************************************************************
changed: [minikube]
TASK [shell] *******************************************************************
[WARNING]: Consider using the file module with owner rather than running
'chown'. If you need to use command because file is insufficient you can add
'warn: false' to this command task or set 'command_warnings=False' in
ansible.cfg to get rid of this message.
changed: [minikube]
TASK [shell] *******************************************************************
changed: [minikube]
TASK [shell] *******************************************************************
changed: [minikube]
TASK [change path] *************************************************************
[WARNING]: Consider using the replace, lineinfile or template module rather
than running 'sed'. If you need to use command because replace, lineinfile or
template is insufficient you can add 'warn: false' to this command task or set
'command_warnings=False' in ansible.cfg to get rid of this message.
changed: [minikube]
PLAY RECAP *********************************************************************
minikube : ok=20 changed=19 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
Comments