summaryrefslogtreecommitdiffstats
path: root/src/vagrant/kubeadm
diff options
context:
space:
mode:
Diffstat (limited to 'src/vagrant/kubeadm')
-rw-r--r--src/vagrant/kubeadm/Vagrantfile34
-rwxr-xr-xsrc/vagrant/kubeadm/deploy.sh9
-rw-r--r--src/vagrant/kubeadm/host_setup.sh50
-rw-r--r--src/vagrant/kubeadm/master_setup.sh11
-rw-r--r--src/vagrant/kubeadm/multus/Dockerfile10
-rw-r--r--src/vagrant/kubeadm/multus/busybox.yaml17
-rw-r--r--src/vagrant/kubeadm/multus/cni_multus.yml88
-rwxr-xr-xsrc/vagrant/kubeadm/multus/multus.sh36
-rw-r--r--src/vagrant/kubeadm/registry_setup.sh35
-rw-r--r--src/vagrant/kubeadm/worker_setup.sh6
10 files changed, 296 insertions, 0 deletions
diff --git a/src/vagrant/kubeadm/Vagrantfile b/src/vagrant/kubeadm/Vagrantfile
new file mode 100644
index 0000000..e861859
--- /dev/null
+++ b/src/vagrant/kubeadm/Vagrantfile
@@ -0,0 +1,34 @@
+$num_workers=2
+
+Vagrant.require_version ">= 1.8.6"
+Vagrant.configure("2") do |config|
+
+ config.vm.box = "ceph/ubuntu-xenial"
+ config.vm.provider :libvirt do |libvirt|
+ libvirt.memory = 4096
+ libvirt.cpus = 4
+ end
+
+ config.vm.define "registry" do |config|
+ config.vm.hostname = "registry"
+ config.vm.provision "shell", path: "registry_setup.sh", privileged: false
+ config.vm.network :private_network, ip: "192.168.1.5"
+ end
+
+ config.vm.define "master" do |config|
+ config.vm.hostname = "master"
+ config.vm.provision "shell", path: "host_setup.sh", privileged: false
+ config.vm.provision "shell", path: "master_setup.sh", privileged: false
+ config.vm.network :private_network, ip: "192.168.1.10"
+ end
+
+ (1 .. $num_workers).each do |i|
+ config.vm.define vm_name = "worker%d" % [i] do |config|
+ config.vm.hostname = vm_name
+ config.vm.provision "shell", path: "host_setup.sh", privileged: false
+ config.vm.provision "shell", path: "worker_setup.sh", privileged: false
+ config.vm.network :private_network, ip: "192.168.1.#{i+20}"
+ end
+ end
+
+end
diff --git a/src/vagrant/kubeadm/deploy.sh b/src/vagrant/kubeadm/deploy.sh
new file mode 100755
index 0000000..c727483
--- /dev/null
+++ b/src/vagrant/kubeadm/deploy.sh
@@ -0,0 +1,9 @@
+#!/bin/bash
+
+set -ex
+DIR="$(dirname `readlink -f $0`)"
+
+cd $DIR
+../cleanup.sh
+vagrant up
+vagrant ssh master -c "/vagrant/multus/multus.sh"
diff --git a/src/vagrant/kubeadm/host_setup.sh b/src/vagrant/kubeadm/host_setup.sh
new file mode 100644
index 0000000..d792119
--- /dev/null
+++ b/src/vagrant/kubeadm/host_setup.sh
@@ -0,0 +1,50 @@
+#!/bin/bash
+
+set -ex
+
+cat << EOF | sudo tee /etc/hosts
+127.0.0.1 localhost
+192.168.1.05 registry
+192.168.1.10 master
+192.168.1.21 worker1
+192.168.1.22 worker2
+192.168.1.23 worker3
+EOF
+
+sudo apt-get update
+sudo apt-get install -y \
+ apt-transport-https \
+ ca-certificates \
+ curl \
+ software-properties-common
+
+curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
+sudo add-apt-repository \
+ "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
+ $(lsb_release -cs) \
+ stable"
+sudo apt-get update
+sudo apt-get install -y docker-ce=18.03.1~ce-0~ubuntu
+cat << EOF | sudo tee /etc/docker/daemon.json
+{
+ "insecure-registries": ["registry:5000"]
+}
+EOF
+sudo service docker restart
+
+curl -s http://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
+cat <<EOF | sudo tee /etc/apt/sources.list.d/kubernetes.list
+deb http://apt.kubernetes.io/ kubernetes-xenial main
+EOF
+sudo apt-get update
+sudo apt-get install -y --allow-unauthenticated kubelet=1.12.2-00 kubeadm=1.12.2-00 kubectl=1.12.2-00 kubernetes-cni=0.6.0-00
+echo 'Environment="KUBELET_EXTRA_ARGS=--feature-gates=DevicePlugins=true"' | sudo tee /etc/default/kubelet
+
+sudo modprobe ip_vs
+sudo modprobe ip_vs_rr
+sudo modprobe ip_vs_wrr
+sudo modprobe ip_vs_sh
+sudo swapoff -a
+sudo systemctl daemon-reload
+sudo systemctl stop kubelet
+sudo systemctl start kubelet
diff --git a/src/vagrant/kubeadm/master_setup.sh b/src/vagrant/kubeadm/master_setup.sh
new file mode 100644
index 0000000..a898d8d
--- /dev/null
+++ b/src/vagrant/kubeadm/master_setup.sh
@@ -0,0 +1,11 @@
+#!/bin/bash
+
+set -ex
+
+sudo kubeadm init --apiserver-advertise-address=192.168.1.10 --service-cidr=10.96.0.0/16 --pod-network-cidr=10.32.0.0/12 --token 8c5adc.1cec8dbf339093f0
+mkdir ~/.kube
+sudo cp /etc/kubernetes/admin.conf $HOME/.kube/config
+sudo chown $(id -u):$(id -g) $HOME/.kube/config
+
+kubectl apply -f http://git.io/weave-kube-1.6
+kubectl apply -f /vagrant/multus/cni_multus.yml
diff --git a/src/vagrant/kubeadm/multus/Dockerfile b/src/vagrant/kubeadm/multus/Dockerfile
new file mode 100644
index 0000000..7923d0d
--- /dev/null
+++ b/src/vagrant/kubeadm/multus/Dockerfile
@@ -0,0 +1,10 @@
+FROM ubuntu:16.04
+ENV PATH="/usr/local/go/bin:$PATH"
+WORKDIR /go/src/
+RUN apt-get update && apt-get install -y wget git gcc
+RUN wget -qO- https://storage.googleapis.com/golang/go1.8.3.linux-amd64.tar.gz | tar -C /usr/local/ -xz
+RUN git clone https://github.com/Intel-Corp/multus-cni
+RUN cd multus-cni; bash ./build
+
+FROM busybox
+COPY --from=0 /go/src/multus-cni/bin/multus /root
diff --git a/src/vagrant/kubeadm/multus/busybox.yaml b/src/vagrant/kubeadm/multus/busybox.yaml
new file mode 100644
index 0000000..7fd1b8d
--- /dev/null
+++ b/src/vagrant/kubeadm/multus/busybox.yaml
@@ -0,0 +1,17 @@
+apiVersion: v1
+kind: ReplicationController
+metadata:
+ name: busybox
+spec:
+ replicas: 2
+ template:
+ metadata:
+ labels:
+ app: busybox
+ spec:
+ containers:
+ - name: busybox
+ image: busybox:1.27.2
+ command:
+ - sleep
+ - "36000"
diff --git a/src/vagrant/kubeadm/multus/cni_multus.yml b/src/vagrant/kubeadm/multus/cni_multus.yml
new file mode 100644
index 0000000..50372ca
--- /dev/null
+++ b/src/vagrant/kubeadm/multus/cni_multus.yml
@@ -0,0 +1,88 @@
+---
+apiVersion: v1
+kind: ServiceAccount
+metadata:
+ name: cnimultus
+ namespace: kube-system
+---
+kind: ConfigMap
+apiVersion: v1
+metadata:
+ name: cnimultus-cfg
+ namespace: kube-system
+ labels:
+ tier: node
+ app: cnimultus
+data:
+ cni-conf.json: |
+ {
+ "name": "multus",
+ "type": "multus",
+ "delegates": [
+ {
+ "name": "weave",
+ "type": "weave-net",
+ "hairpinMode": true,
+ "masterplugin": true
+ },
+ {
+ "name": "mynet",
+ "type": "bridge",
+ "bridge": "cni0",
+ "isGateway": true,
+ "ipMasq": true,
+ "ipam": {
+ "type": "host-local",
+ "subnet": "10.22.0.0/16",
+ "routes": [
+ { "dst": "0.0.0.0/0" }
+ ]
+ }
+ }
+ ]
+ }
+---
+apiVersion: extensions/v1beta1
+kind: DaemonSet
+metadata:
+ name: cnimultus-ds
+ namespace: kube-system
+ labels:
+ tier: node
+ app: cnimultus
+spec:
+ template:
+ metadata:
+ labels:
+ tier: node
+ app: cnimultus
+ spec:
+ hostNetwork: true
+ nodeSelector:
+ beta.kubernetes.io/arch: amd64
+ tolerations:
+ - key: node-role.kubernetes.io/master
+ operator: Exists
+ effect: NoSchedule
+ serviceAccountName: cnimultus
+ containers:
+ - name: run-cni
+ image: registry:5000/multus-cni
+ command: ['sh', '-c', 'cp /multus/cni-conf.json /etc/cni/net.d/05-multus.conf; cp /root/multus /opt/cni/bin; while true; do sleep 10000; done' ]
+ volumeMounts:
+ - name: cni-bin
+ mountPath: /opt/cni/bin
+ - name: etc-cni
+ mountPath: /etc/cni/net.d
+ - name: cnimultus-cfg
+ mountPath: /multus/
+ volumes:
+ - name: cni-bin
+ hostPath:
+ path: /opt/cni/bin
+ - name: etc-cni
+ hostPath:
+ path: /etc/cni/net.d
+ - name: cnimultus-cfg
+ configMap:
+ name: cnimultus-cfg
diff --git a/src/vagrant/kubeadm/multus/multus.sh b/src/vagrant/kubeadm/multus/multus.sh
new file mode 100755
index 0000000..9461a6f
--- /dev/null
+++ b/src/vagrant/kubeadm/multus/multus.sh
@@ -0,0 +1,36 @@
+#!/bin/bash
+#
+# Copyright (c) 2017 Intel Corporation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+set -ex
+
+while true
+do
+ kubectl get pods -n kube-system | grep kube-cnimultus-ds | grep -v Run | wc -l | grep "^0$" && break
+ sleep 60
+done
+
+kubectl delete rc --all
+kubectl apply -f /vagrant/multus/busybox.yaml
+r="0"
+while [ $r -ne "2" ]
+do
+ r=$(kubectl get pods | grep Running | wc -l)
+ sleep 60
+done
+
+kubectl get pods --all-namespaces
+kubectl get pods | grep Run | sed "s/ .*//" | xargs -I {} kubectl exec -i {} ip a | grep mtu | wc -l | grep "^6$" || exit 1
diff --git a/src/vagrant/kubeadm/registry_setup.sh b/src/vagrant/kubeadm/registry_setup.sh
new file mode 100644
index 0000000..188502d
--- /dev/null
+++ b/src/vagrant/kubeadm/registry_setup.sh
@@ -0,0 +1,35 @@
+#!/bin/bash
+
+set -ex
+
+cat << EOF | sudo tee /etc/hosts
+127.0.0.1 localhost
+192.168.1.5 registry
+EOF
+
+sudo apt-get update
+sudo apt-get install -y \
+ apt-transport-https \
+ ca-certificates \
+ curl \
+ software-properties-common
+
+curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
+sudo add-apt-repository \
+ "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
+ $(lsb_release -cs) \
+ stable"
+sudo apt-get update
+sudo apt-get install -y docker-ce=18.06.0~ce~3-0~ubuntu
+cat << EOF | sudo tee /etc/docker/daemon.json
+{
+ "insecure-registries": ["registry:5000"]
+}
+EOF
+sudo service docker restart
+
+sudo docker pull registry:2
+sudo docker run -d -p 5000:5000 --restart=always --name registry registry:2
+sudo docker build . -f /vagrant/multus/Dockerfile -t multus-cni
+sudo docker tag multus-cni localhost:5000/multus-cni
+sudo docker push localhost:5000/multus-cni
diff --git a/src/vagrant/kubeadm/worker_setup.sh b/src/vagrant/kubeadm/worker_setup.sh
new file mode 100644
index 0000000..858cafd
--- /dev/null
+++ b/src/vagrant/kubeadm/worker_setup.sh
@@ -0,0 +1,6 @@
+#!/bin/bash
+
+set -ex
+
+sleep 120
+sudo kubeadm join --discovery-token-unsafe-skip-ca-verification --token 8c5adc.1cec8dbf339093f0 192.168.1.10:6443