The chapter 'Provisioning Compute Resources' is updated.

pull/443/head
Pick1a1username 2019-02-17 18:35:39 +09:00
parent 5a4bd7cf3c
commit feb74148a6
1 changed files with 78 additions and 63 deletions

View File

@ -11,15 +11,14 @@ The Kubernetes [networking model](https://kubernetes.io/docs/concepts/cluster-ad
### Virtual Network ### Virtual Network
In this section Virtual Network will be setup to host the Kubernetes cluster. In this section, Virtual Network will be setup to host the Kubernetes cluster.
1. Open Virtual Machine Manager, and from menu, go to Edit -> Connection Details. 1. Open Virtual Machine Manager, and from menu, go to `Edit` -> `Connection Details`.
2. Go to Virtual Networks tab, and click the plus(+) button at the left lower side of the window. 2. Go to `Virtual Networks` tab, and click the plus(+) button at the left lower side of the window.
3. Type `kubernetes-nw` in the textbox named `Network Name`, and click Forward. 3. Type `kubernetes-nw` in the textbox named `Network Name`, and click Forward.
4. Type `10.240.0.0/24` in the textbox named `Network`, type `10.240.0.2` in the textbox named `Start`, type `10.240.0.254` in the textbox named `end`, and click Forward. 4. Type `10.240.0.0/24` in the textbox named `Network`, type `10.240.0.2` in the textbox named `Start`, type `10.240.0.254` in the textbox named `end`, and click Forward.
5. You will be asked whether enabling IPv6 or not. Don't check the checkbox, and click Forward. 5. You will be asked whether enabling IPv6 or not. Don't check the checkbox, and click `Forward`.
6. Click the radiobutton named `Forwarding to physical network`, type `kubernetes-nw.com` in the textbox named `DNS Domain Name`, and click Finish. 6. Click the radiobutton named `Forwarding to physical network`, type `kubernetes-nw.com` in the textbox named `DNS Domain Name`, and click `Finish`.
7. Click the network created above, and take a note of the value of Device. This value will be needed when setting routing.
## Virtual Machines ## Virtual Machines
@ -44,14 +43,14 @@ The following virtual machines will be setup in this chapter:
As installing OS to each virtual machine manually is time-consuming, using a base image where OS is already installed is very handy. As installing OS to each virtual machine manually is time-consuming, using a base image where OS is already installed is very handy.
In this tutorial, `ubuntu-xenial.qcow2` is assumed to be the base image. In this chapter, `ubuntu-xenial.qcow2` is assumed to be the base image.
### Kubernetes Controllers ### Kubernetes Controllers
Create three virtual instances which will host the Kubernetes control plane: Create three virtual instances which will host the Kubernetes control plane:
1. Open a terminal, or login to the linux server, and move to the directory where the base image exists (maybe `/var/lib/libvirt/images`?). 1. Open a terminal, or login to the KVM host, and move to the directory where the base image exists (maybe `/var/lib/libvirt/images`?).
2. Create images for Kubernetes controllers backed by the base image: 2. Create images for Kubernetes controllers backed by the base image:
``` ```
@ -62,19 +61,16 @@ Create three virtual instances which will host the Kubernetes control plane:
(Using each image created above, repeat from 3. to 7..) (Using each image created above, repeat from 3. to 7..)
3. Open Virtual Machine Manager, and click the icon named 'Create a new virtual machine'. 3. Open Virtual Machine Manager, and click the icon named `Create a new virtual machine`.
4. Check the radiobutton named `Importing existing disk image`, and click Forward 4. Check the radiobutton named `Importing existing disk image`, and click `Forward`.
5. Click Browse, click the n-th controller image, click Choose Volume, choose the operating system (`Ubuntu 16.04` in this case), and click Forward. 5. Click `Browse`, click the n-th controller image, click Choose Volume, choose the operating system (`Ubuntu 16.04` in this case), and click `Forward`.
6. Type `512` in the textbox named `Memory`, and click Forward. 6. Type `512` in the textbox named `Memory`, and click Forward.
7. Type `controller-n`, click Network selection, select the network `kubernetes-nw`, and click Finish. 7. Type `controller-n`(`n` should be `1`, `2`, or `3`), click `Network selection`, select the network `kubernetes-nw`, and click `Finish`.
(Todo: Setup Network Interface)
### Kubernetes Workers ### Kubernetes Workers
Each worker instance requires a pod subnet allocation from the Kubernetes cluster CIDR range. The pod subnet allocation will be used to configure container networking in a later exercise. The `pod-cidr` instance metadata will be used to expose pod subnet allocations to compute instances at runtime. Each worker instance requires a pod subnet allocation from the Kubernetes cluster CIDR range. The pod subnet allocation will be used to configure container networking in a later chapter.
> The Kubernetes cluster CIDR range is defined by the Controller Manager's `--cluster-cidr` flag. In this tutorial the cluster CIDR range will be set to `10.200.0.0/16`, which supports 254 subnets. > The Kubernetes cluster CIDR range is defined by the Controller Manager's `--cluster-cidr` flag. In this tutorial the cluster CIDR range will be set to `10.200.0.0/16`, which supports 254 subnets.
@ -91,37 +87,33 @@ Create three virtual machines which will host the Kubernetes worker nodes:
(Using each image created above, repeat from 3. to 7..) (Using each image created above, repeat from 3. to 7..)
3. Open Virtual Machine Manager, and click the icon named 'Create a new virtual machine'. 3. Open Virtual Machine Manager, and click the icon named `Create a new virtual machine`.
4. Check the radiobutton named `Importing existing disk image`, and click Forward 4. Check the radiobutton named `Importing existing disk image`, and click `Forward`.
5. Click Browse, click the n-th controller image, click Choose Volume, choose the operating system (`Ubuntu 16.04` in this case), and click Forward. 5. Click `Browse`, click the n-th controller image, click `Choose Volume`, choose the operating system (`Ubuntu 16.04` in this case), and click `Forward`.
6. Type `512` in the textbox named `Memory`, and click Forward. 6. Type `1024` in the textbox named `Memory`, and click `Forward`.
7. Type `worker-n`, click Network selection, select the network `kubernetes-nw`, and click Finish. 7. Type `worker-n`(`n` should be `1`, `2`, or `3`), click `Network selection`, select the network `kubernetes-nw`, and click `Finish`.
(Todo: Setup Network Interface)
### Load Balancer for Kubernetes API Server ### Load Balancer for Kubernetes API Server
Kuberentes API Server...
1. Open a terminal, or login to the KVM host, and move to the directory where the base image exists (maybe `/var/lib/libvirt/images`?).
1. Open a terminal, or login to the linux server, and move to the directory where the base image exists (maybe `/var/lib/libvirt/images`?).
2. Create images for Kubernetes controllers backed by the base image: 2. Create images for Kubernetes controllers backed by the base image:
``` ```
# qemu-img create -f qcow2 ubuntu-xenial.qcow -b ubuntu-xenial-lb-1.qcow2 # qemu-img create -f qcow2 ubuntu-xenial.qcow -b ubuntu-xenial-lb-1.qcow2
``` ```
3. Open Virtual Machine Manager, and click the icon named 'Create a new virtual machine'. 3. Open Virtual Machine Manager, and click the icon named `Create a new virtual machine`.
4. Check the radiobutton named `Importing existing disk image`, and click Forward 4. Check the radiobutton named `Importing existing disk image`, and click `Forward`.
5. Click Browse, click the n-th controller image, click Choose Volume, choose the operating system (`Ubuntu 16.04` in this case), and click Forward. 5. Click `Browse`, click the load balancer's image, click `Choose Volume`, choose the operating system (`Ubuntu 16.04` in this case), and click `Forward`.
6. Type `512` in the textbox named `Memory`, and click Forward. 6. Type `256` in the textbox named `Memory`, and click `Forward`.
7. Type `lb-1`, click Network selection, select the network `kubernetes-nw`, and click Finish. 7. Type `lb-1`, click `Network selection`, select the network `kubernetes-nw`, and click `Finish`.
### Client for Kubernetes ### Client for Kubernetes
Create a virtual machine, instead of Cloud Shell in GCP, that will be used as a client for Kubernetes. Instead of Cloud Shell in GCP, create a virtual machine that will be used as a client for Kubernetes.
1. Open a terminal, or login to the linux server, and move to the directory where the base image exists (maybe `/var/lib/libvirt/images`?). 1. Open a terminal, or login to the linux server, and move to the directory where the base image exists (maybe `/var/lib/libvirt/images`?).
@ -130,11 +122,11 @@ Create a virtual machine, instead of Cloud Shell in GCP, that will be used as a
``` ```
# qemu-img create -f qcow2 ubuntu-xenial.qcow -b ubuntu-xenial-client-1.qcow2 # qemu-img create -f qcow2 ubuntu-xenial.qcow -b ubuntu-xenial-client-1.qcow2
``` ```
3. Open Virtual Machine Manager, and click the icon named 'Create a new virtual machine'. 3. Open Virtual Machine Manager, and click the icon named `Create a new virtual machine`.
4. Check the radiobutton named `Importing existing disk image`, and click Forward 4. Check the radiobutton named `Importing existing disk image`, and click `Forward`.
5. Click Browse, click the n-th controller image, click Choose Volume, choose the operating system (`Ubuntu 16.04` in this case), and click Forward. 5. Click `Browse`, click the client's image, click `Choose Volume`, choose the operating system (`Ubuntu 16.04` in this case), and click `Forward`.
6. Type `512` in the textbox named `Memory`, and click Forward. 6. Type `512` in the textbox named `Memory`, and click `Forward`.
7. Type `client-1`, click Network selection, select the network `kubernetes-nw`, and click Finish. 7. Type `client-1`, click `Network selection`, select the network `kubernetes-nw`, and click `Finish`.
## Configuring Virtual Machines ## Configuring Virtual Machines
@ -146,7 +138,7 @@ As described above, the IP address of each virtual machine should be fixed.
Referring to the environment information described above, Set the IP Address to each virtual machine. Referring to the environment information described above, Set the IP Address to each virtual machine.
1. Login to the virtual machine. 1. Through SSH or Graphic Console by Virtual Machine Manager, login to the virtual machine.
2. Set the hostname: 2. Set the hostname:
``` ```
@ -190,30 +182,11 @@ $ sudo reboot
``` ```
### Modifying `hosts`
Though resolving hostnames is unnecessary, ...
1. In the host PC, create a text file listing IP addresses and hostnames:
```
$ cat << EOF > new_hosts
10.240.0.11 controller-1
10.240.0.12 controller-2
10.240.0.13 controller-3
10.240.0.10 lb-1
10.240.0.21 worker-1
10.240.0.22 worker-2
10.240.0.23 worker-3
10.240.0.99 client-1
EOF
```
## Configuring SSH Access ## Configuring SSH Access
SSH will be used to configure the controller and worker instances. SSH will be used to configure the controller and worker nodes.
1. In the host PC, generate a SSH key. 1. In `client-1`, generate a SSH key.
``` ```
$ ssh-keygen $ ssh-keygen
@ -255,22 +228,64 @@ $ cat << EOF > target_hosts.txt
10.240.0.21 10.240.0.21
10.240.0.22 10.240.0.22
10.240.0.23 10.240.0.23
10.240.0.99
EOF EOF
``` ```
3. Distribute the key to the virtual machines. 3. Distribute the key to the virtual machines.
``` ```
$ for target in `cat target_hosts`; do ssh-copy-id -i ~/.ssh/id_rsa-k8s.pub <ID>@$target; done $ for target in `cat target_hosts`; do ssh-copy-id -i ~/.ssh/id_rsa-k8s.pub <your username>@$target; done
``` ```
You will be asked to enter password of the user(ID). You will be asked to enter password of the user(ID).
4. Verify ... 4. Verify it.
``` ```
$ do ssh -i ~/.ssh/id_rsa-k8s <ID>@$target uname -n; done $ do ssh -i ~/.ssh/id_rsa-k8s <your username>@$target uname -n; done
``` ```
### Modifying `hosts`
1. In `client-1`, create a text file listing IP addresses and hostnames.
```
$ cat << EOF > new_hosts
10.240.0.10 lb-1
10.240.0.11 controller-1
10.240.0.12 controller-2
10.240.0.13 controller-3
10.240.0.21 worker-1
10.240.0.22 worker-2
10.240.0.23 worker-3
10.240.0.99 client-1
EOF
```
2. Add new hosts to `client-1`.
```
$ sudo cat new_hosts >> /etc/hosts
```
3. Distribute `new_hosts` to the other virtual machines.
```
$ for i in `cat target_hosts.txt`; \
do scp -i ~/.ssh/id_rsa-k8s new_hosts <your username>@$target:~/; \
done
```
4. Login to each virtual machines to which `new_hosts` is sent to, add `new_hosts` to `/etc/hosts`.
(`tmux` can make this procedure done simply)
```
$ ssh -i ~/.ssh/id_rsa-k8s <Your Username>@<IP Address>
$ sudo cat new_hosts >> /etc/hosts
$ rm new_hosts
```
Next: [Provisioning a CA and Generating TLS Certificates](04-certificate-authority.md) Next: [Provisioning a CA and Generating TLS Certificates](04-certificate-authority.md)