Build Base VM
Issue the following commands on your vm. The master node will require 2 cores and 2GB memory.
Update apt-get
> sudo su > apt-get update
Install openssh
> apt-get install openssh-server
Enable both network interfaces
If you are installing Ubuntu server it will enable a primary network interface.
For VirtualBox VMs we are using 2 network interfaces:
- a NAT network used for accessing the internet (primary)
- a host only network for accessing the host from our machine without having to setup port forwarding.
>ifconfig -a
Add the missing interface to your interfaces config file and reboot
> vi /etc/network/interfaces
# This file describes the network interfaces available on your system # and how to activate them. For more information, see interfaces(5). source /etc/network/interfaces.d/* # The loopback network interface auto lo iface lo inet loopback # The primary network interface auto enp0s8 iface enp0s8 inet dhcp auto enp0s3 iface enp0s3 inet dhcp
> reboot
Login and get IP address:
> ifconfig
enp0s3 Link encap:Ethernet HWaddr 08:00:27:56:82:00 inet addr:192.168.56.3 Bcast:192.168.56.255 Mask:255.255.255.0 inet6 addr: fe80::a00:27ff:fe56:8200/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:170 errors:0 dropped:0 overruns:0 frame:0 TX packets:112 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:18488 (18.4 KB) TX bytes:19156 (19.1 KB) enp0s8 Link encap:Ethernet HWaddr 08:00:27:f0:a2:f5 inet addr:10.0.3.15 Bcast:10.0.3.255 Mask:255.255.255.0 inet6 addr: fe80::a00:27ff:fef0:a2f5/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:329 errors:0 dropped:0 overruns:0 frame:0 TX packets:141 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:389613 (389.6 KB) TX bytes:10690 (10.6 KB) ...
Now you can ssh into the virtual machine on the host-only network from your host
> ssh test@192.168.56.3
Install Docker
> sudo su
> apt-get install -y docker.io
Install Curl
> apt-get install -y apt-transport-https curl
Install Kubernetes
> curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
cat <<EOF >/etc/apt/sources.list.d/kubernetes.list deb https://apt.kubernetes.io/ kubernetes-xenial main EOF
> apt-get update
> apt-get install -y kubelet kubeadm kubectl
> apt-mark hold kubelet kubeadm kubectl
Pull images
> kubeadm config images pull
[config/images] Pulled k8s.gcr.io/kube-apiserver:v1.13.1 [config/images] Pulled k8s.gcr.io/kube-controller-manager:v1.13.1 [config/images] Pulled k8s.gcr.io/kube-scheduler:v1.13.1 [config/images] Pulled k8s.gcr.io/kube-proxy:v1.13.1 [config/images] Pulled k8s.gcr.io/pause:3.1 [config/images] Pulled k8s.gcr.io/etcd:3.2.24 [config/images] Pulled k8s.gcr.io/coredns:1.2.6
Now clone this VM with names:
- k8master
- k8worker1
- k8worker2
Setup Networking on VMs
On the VMs that we have defined, lets get them configured.
VM | Ip Address |
---|---|
k8master | 192.168.56.100 |
k8worker1 | 192.168.56.101 |
k8worker2 | 192.168.56.102 |
Set Hostname
> vi /etc/hostname
k8master
> vi /etc/hosts
127.0.0.1 localhost 127.0.1.1 k8master # The following lines are desirable for IPv6 capable hosts ::1 localhost ip6-localhost ip6-loopback ff02::1 ip6-allnodes ff02::2 ip6-allrouters
Set IP address
Set a static ip address for our host-only interface (enp0s3)
> sudo su
> vi /etc/network/interfaces
# This file describes the network interfaces available on your system # and how to activate them. For more information, see interfaces(5). source /etc/network/interfaces.d/* # The loopback network interface auto lo iface lo inet loopback # The primary network interface auto enp0s8 iface enp0s8 inet dhcp auto enp0s3 iface enp0s3 inet static address 192.168.56.100 netmask 255.255.255.0 network 192.168.56.0 broadcast 192.168.56.255
Disable SWAP
> swapoff -va
> vi /etc/fstab
|
> reboot
Repeat for all VMs
Initialize Master
> sudo kubeadm init --apiserver-advertise-address 192.168.56.100 --pod-network-cidr 192.168.0.0/16
... Your Kubernetes master has initialized successfully! To start using your cluster, you need to run the following as a regular user: mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/config You should now deploy a pod network to the cluster. Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at: https://kubernetes.io/docs/concepts/cluster-administration/addons/ You can now join any number of machines by running the following on each node as root: kubeadm join 192.168.56.100:6443 --token gi6ugh.jufhrmb9rrcxn95c --discovery-token-ca-cert-hash sha256:6c9406ae054946f8f33122a8acf1afb9ae560d8aeffff3969c1f2218e4ddf9bb
As your non root user:
> mkdir -p $HOME/.kube
> sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
> sudo chown $(id -u):$(id -g) $HOME/.kube/config
Join Worker Nodes
User kubeadm join to join the cluster.
> kubeadm join 192.168.56.100:6443 --token gi6ugh.jufhrmb9rrcxn95c --discovery-token-ca-cert-hash sha256:6c9406ae054946f8f33122a8acf1afb9ae560d8aeffff3969c1f2218e4ddf9bb