Build 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
Disable SWAP
> swapoff -va
> vi /etc/fstab
# /etc/fstab: static file system information. # # Use 'blkid' to print the universally unique identifier for a # device; this may be used with UUID= as a more robust way to name devices # that works even if disks are added and removed. See fstab(5). # # <file system> <mount point> <type> <options> <dump> <pass> # / was on /dev/sda1 during installation UUID=e7b204f7-9f41-42d4-b55f-292990f4137a / ext4 errors=remount-ro 0 1 # swap was on /dev/sda5 during installation #UUID=9ca9f4cb-876e-4e23-91a4-2f543b5537ac none swap sw 0 0
Now clone this VM with names:
- k8master
- k8worker1
- k8worker2
- k8worker3
Setup Network
Initialize Master
> kubeadm init
... 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 10.0.2.100:6443 --token 8616y5.99svelizti79sgyw --discovery-token-ca-cert-hash sha256:b3631a1b774382f980ac6e8e881241f59eccc5ff250ffc948e001e9aff40cbb7