Saturday, December 28, 2019

K8s(kurbernetes 1.17) provisioning with vagrant and kvm(libvirt).

Prequisites).
In thie blog post, I will show how to provision k8s 1.17 with vagrant and some shell scripts.

Ubuntu18.04,vagrant and kvm environment.

*First of all, we should install vagrant and libvirt plugin.


oyj@controller:~$ vagrant plugin list
==> vagrant: A new version of Vagrant is available: 2.2.6 (installed version: 2.2.5)!
==> vagrant: To upgrade visit: https://www.vagrantup.com/downloads.html

vagrant-libvirt (0.0.45, global)

#If we did not install libvirt plugin, install like below.
oyj@controller:~$ vagrant plugin install libvirt
Installing the 'libvirt' plugin. This can take a few minutes...


*Second of all, we should clone git repo that I created recently.

oyj@controller:~$ git clone https://github.com/ohyoungjooung2/u18kvk8s.git
Cloning into 'u18kvk8s'...
remote: Enumerating objects: 216, done.
remote: Counting objects: 100% (216/216), done.
remote: Compressing objects: 100% (173/173), done.
remote: Total 216 (delta 36), reused 207 (delta 32), pack-reused 0
Receiving objects: 100% (216/216), 894.49 KiB | 942.00 KiB/s, done.
Resolving deltas: 100% (36/36), done.

*Lastly, just execute setup.sh.

oyj@controller:~$ cd u18kvk8s/k8s/
ooyj@controller:~/u18kvk8s/k8s$ bash setup.sh
Deleting previous id_rsa
 Generating ssh key for provisionng automatic
 copy id_rsa.put to pub_key
 up master first
Bringing machine 'kubemaster' up with 'libvirt' provider...
==> kubemaster: Checking if box 'centos/7' version '1905.1' is up to date...
==> kubemaster: Creating image (snapshot of base box volume).
==> kubemaster: Creating domain with the following settings...
==> kubemaster:  -- Name:              k8s_kubemaster
==> kubemaster:  -- Domain type:       kvm
==> kubemaster:  -- Cpus:              2
==> kubemaster:  -- Feature:           acpi
==> kubemaster:  -- Feature:           apic
==> kubemaster:  -- Feature:           pae
==> kubemaster:  -- Memory:            2048M
==> kubemaster:  -- Management MAC:   
==> kubemaster:  -- Loader:           
==> kubemaster:  -- Nvram:            
==> kubemaster:  -- Base box:          centos/7
==> kubemaster:  -- Storage pool:      default
==> kubemaster:  -- Image:             /var/lib/libvirt/images/k8s_kubemaster.img (41G)
==> kubemaster:  -- Volume Cache:      default
==> kubemaster:  -- Kernel:           
==> kubemaster:  -- Initrd:           
==> kubemaster:  -- Graphics Type:     vnc
==> kubemaster:  -- Graphics Port:     -1
==> kubemaster:  -- Graphics IP:       127.0.0.1
==> kubemaster:  -- Graphics Password: Not defined
==> kubemaster:  -- Video Type:        cirrus
==> kubemaster:  -- Video VRAM:        9216
==> kubemaster:  -- Sound Type:   
==> kubemaster:  -- Keymap:            en-us
==> kubemaster:  -- TPM Path:         
==> kubemaster:  -- INPUT:             type=mouse, bus=ps2
==> kubemaster: Creating shared folders metadata...
==> kubemaster: Starting domain.
==> kubemaster: Waiting for domain to get an IP address...
==> kubemaster: Waiting for SSH to become available...
    kubemaster:


===============omitted..too long ====================

Password authentication is disabled to avoid man-in-the-middle attacks.
Keyboard-interactive authentication is disabled to avoid man-in-the-middle attacks.
admin_init.log                                100% 4605     7.0MB/s   00:00   
scp admin_inig.log success
Wait until kubemaster ready to accept nodes to join

kubeworker2: Warning: Permanently added '10.1.0.2' (ECDSA) to the list of known hosts.
    kubeworker2:  Node will join with master 10.1.0.2
    kubeworker2: [preflight] Running pre-flight checks
    kubeworker2: W1228 11:31:10.356519    6787 join.go:346] [preflight] WARNING: JoinControlPane.controlPlane settings will be ignored when control-plane flag is not set.
    kubeworker2: [preflight] Reading configuration from the cluster...
    kubeworker2: [preflight] FYI: You can look at this config file with 'kubectl -n kube-system get cm kubeadm-config -oyaml'
    kubeworker2: [kubelet-start] Downloading configuration for the kubelet from the "kubelet-config-1.17" ConfigMap in the kube-system namespace
    kubeworker2: [kubelet-start] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml"
    kubeworker2: [kubelet-start] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env"
    kubeworker2: [kubelet-start] Starting the kubelet
    kubeworker2: [kubelet-start] Waiting for the kubelet to perform the TLS Bootstrap...
    kubeworker2:
    kubeworker2: This node has joined the cluster:
    kubeworker2: * Certificate signing request was sent to apiserver and a response was received.
    kubeworker2: * The Kubelet was informed of the new secure connection details.
    kubeworker2:
    kubeworker2: Run 'kubectl get nodes' on the control-plane to see this node join the cluster.



* And we can check by logging in kubemaster node.

oyj@controller:~/u18kvk8s/k8s$ vagrant ssh kubemaster
Last login: Sat Dec 28 11:20:50 2019
[vagrant@kubemaster ~]$ kubectl get nodes
NAME          STATUS   ROLES    AGE     VERSION
kubemaster    Ready    master   14m     v1.17.0
kubeworker1   Ready    <none>   5m34s   v1.17.0
kubeworker2   Ready    <none>   2m48s   v1.17.0



Conclusion).
To sum up, we can create k8s environment with vagrant and some shell scripts. Easy!..^^.

Thanks for reading.