From 79c38bff1b279a6d73bbbffd98f44613d76afbfe Mon Sep 17 00:00:00 2001 From: Guo Ruijing Date: Thu, 3 Aug 2017 08:42:12 -0700 Subject: deploy ovsdpdk by k8s Change-Id: Ie8ea880db410e699cdda147b304705819e13157a Signed-off-by: Guo Ruijing --- src/vagrant/k8s_kubeadm/Vagrantfile | 7 +++ src/vagrant/k8s_kubeadm/examples/virtio-user.yaml | 29 +++++++++++++ src/vagrant/k8s_kubeadm/host_setup.sh | 19 ++++++++ src/vagrant/k8s_kubeadm/master_setup.sh | 23 ++-------- src/vagrant/k8s_kubeadm/ovsdpdk/Dockerfile | 8 ++++ src/vagrant/k8s_kubeadm/ovsdpdk/install.sh | 7 +++ src/vagrant/k8s_kubeadm/ovsdpdk/kube_ovsdpdk.yml | 53 +++++++++++++++++++++++ src/vagrant/k8s_kubeadm/ovsdpdk/start.sh | 15 +++++++ src/vagrant/k8s_kubeadm/worker_setup.sh | 22 +--------- 9 files changed, 144 insertions(+), 39 deletions(-) create mode 100644 src/vagrant/k8s_kubeadm/examples/virtio-user.yaml create mode 100644 src/vagrant/k8s_kubeadm/host_setup.sh create mode 100644 src/vagrant/k8s_kubeadm/ovsdpdk/Dockerfile create mode 100644 src/vagrant/k8s_kubeadm/ovsdpdk/install.sh create mode 100644 src/vagrant/k8s_kubeadm/ovsdpdk/kube_ovsdpdk.yml create mode 100644 src/vagrant/k8s_kubeadm/ovsdpdk/start.sh diff --git a/src/vagrant/k8s_kubeadm/Vagrantfile b/src/vagrant/k8s_kubeadm/Vagrantfile index 3baf072..3890e57 100644 --- a/src/vagrant/k8s_kubeadm/Vagrantfile +++ b/src/vagrant/k8s_kubeadm/Vagrantfile @@ -4,9 +4,14 @@ Vagrant.require_version ">= 1.8.6" Vagrant.configure("2") do |config| config.vm.box = "bento/ubuntu-16.04" + config.vm.synced_folder "../..", "/src" + config.vm.provision "shell", path: "host_setup.sh", privileged: false config.vm.provider :virtualbox do |vb| vb.customize ["modifyvm", :id, "--memory", 4096] vb.customize ["modifyvm", :id, "--cpus", 4] + vb.customize ["modifyvm", :id, "--nicpromisc3", "allow-all"] + vb.customize ["setextradata", :id, "VBoxInternal/CPUM/SSE4.1", "1"] + vb.customize ["setextradata", :id, "VBoxInternal/CPUM/SSE4.2", "1"] vb.customize "post-boot",["controlvm", :id, "setlinkstate1", "on"] end @@ -14,6 +19,7 @@ Vagrant.configure("2") do |config| config.vm.hostname = "master" config.vm.provision "shell", path: "master_setup.sh", privileged: false config.vm.network :private_network, ip: "192.168.1.10" + config.vm.network :private_network, ip: "192.168.2.10" end (1 .. $num_workers).each do |i| @@ -21,6 +27,7 @@ Vagrant.configure("2") do |config| config.vm.hostname = vm_name config.vm.provision "shell", path: "worker_setup.sh", privileged: false config.vm.network :private_network, ip: "192.168.1.#{i+20}" + config.vm.network :private_network, ip: "192.168.2.#{i+20}" end end diff --git a/src/vagrant/k8s_kubeadm/examples/virtio-user.yaml b/src/vagrant/k8s_kubeadm/examples/virtio-user.yaml new file mode 100644 index 0000000..9ab1e06 --- /dev/null +++ b/src/vagrant/k8s_kubeadm/examples/virtio-user.yaml @@ -0,0 +1,29 @@ +apiVersion: v1 +kind: ReplicationController +metadata: + name: virtiouser +spec: + replicas: 2 + template: + metadata: + labels: + app: virtiouser + spec: + containers: + - name: virtiouser + image: openretriever/virtio-user-ping + volumeMounts: + - mountPath: /dev/hugepages + name: hugepage-volume + - mountPath: /var/run + name: vhost-volume + command: + - /root/setup_virtio_user.sh + volumes: + - name: hugepage-volume + hostPath: + path: /dev/hugepages + - name: vhost-volume + hostPath: + path: /var/run + restartPolicy: Always diff --git a/src/vagrant/k8s_kubeadm/host_setup.sh b/src/vagrant/k8s_kubeadm/host_setup.sh new file mode 100644 index 0000000..990df7f --- /dev/null +++ b/src/vagrant/k8s_kubeadm/host_setup.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +set -ex + +cat << EOF | sudo tee /etc/hosts +127.0.0.1 localhost +192.168.1.10 master +192.168.1.21 worker1 +192.168.1.22 worker2 +192.168.1.23 worker3 +EOF + +curl -s http://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add - +cat <> $HOME/.bash_profile kubectl apply -f http://git.io/weave-kube-1.6 #kubectl apply -f http://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml #kubectl apply -f http://docs.projectcalico.org/v2.1/getting-started/kubernetes/installation/hosted/kubeadm/1.6/calico.yaml +#kubectl apply -f /vagrant/k8s_kubeadm/dpdk/kube_ovsdpdk.yml +#kubectl apply -f /src/cni/ovsdpdk/kube_ovsdpdk.yml diff --git a/src/vagrant/k8s_kubeadm/ovsdpdk/Dockerfile b/src/vagrant/k8s_kubeadm/ovsdpdk/Dockerfile new file mode 100644 index 0000000..a63df8f --- /dev/null +++ b/src/vagrant/k8s_kubeadm/ovsdpdk/Dockerfile @@ -0,0 +1,8 @@ +FROM ubuntu:16.04 + +WORKDIR /ovsdpdk +RUN apt-get update && apt-get install -y sudo +ADD install.sh . +RUN bash ./install.sh +ADD start.sh . +RUN chmod 755 start.sh diff --git a/src/vagrant/k8s_kubeadm/ovsdpdk/install.sh b/src/vagrant/k8s_kubeadm/ovsdpdk/install.sh new file mode 100644 index 0000000..66fb71d --- /dev/null +++ b/src/vagrant/k8s_kubeadm/ovsdpdk/install.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +set -ex +sudo apt-get update +sudo apt-get install -y openvswitch-switch-dpdk linux-image-extra-4.4.0-75-generic +sudo update-alternatives --set ovs-vswitchd /usr/lib/openvswitch-switch-dpdk/ovs-vswitchd-dpdk +echo "DPDK_OPTS='--dpdk -c 0x1 -n 4 -m 1024'" | sudo tee -a /etc/default/openvswitch-switch diff --git a/src/vagrant/k8s_kubeadm/ovsdpdk/kube_ovsdpdk.yml b/src/vagrant/k8s_kubeadm/ovsdpdk/kube_ovsdpdk.yml new file mode 100644 index 0000000..d79da15 --- /dev/null +++ b/src/vagrant/k8s_kubeadm/ovsdpdk/kube_ovsdpdk.yml @@ -0,0 +1,53 @@ +--- +apiVersion: v1 +kind: ServiceAccount +metadata: + name: ovsdpdk + namespace: kube-system +--- +apiVersion: extensions/v1beta1 +kind: DaemonSet +metadata: + name: kube-ovsdpdk-ds + namespace: kube-system + labels: + tier: node + app: ovsdpdk +spec: + template: + metadata: + labels: + tier: node + app: ovsdpdk + spec: + hostNetwork: true + nodeSelector: + beta.kubernetes.io/arch: amd64 + tolerations: + - key: node-role.kubernetes.io/master + operator: Exists + effect: NoSchedule + serviceAccountName: ovsdpdk + containers: + - name: install-ovsdpdk + image: openretriever/ubuntu1604-ovsdpdk + command: [ "/bin/bash", "/ovsdpdk/start.sh" ] + securityContext: + privileged: true + volumeMounts: + - name: local-bin + mountPath: /usr/local/bin + - name: var-run + mountPath: /var/run/openvswitch + - name: dev-hugepage + mountPath: /dev + volumes: + - name: local-bin + hostPath: + path: /usr/local/bin + - name: var-run + hostPath: + path: /var/run/openvswitch + - name: dev-hugepage + hostPath: + path: /dev diff --git a/src/vagrant/k8s_kubeadm/ovsdpdk/start.sh b/src/vagrant/k8s_kubeadm/ovsdpdk/start.sh new file mode 100644 index 0000000..08d8143 --- /dev/null +++ b/src/vagrant/k8s_kubeadm/ovsdpdk/start.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +set -ex +sudo sysctl -w vm.nr_hugepages=2048 +sudo mount -t hugetlbfs -o pagesize=2M none /dev/hugepages +cp /usr/bin/ovs-vsctl /usr/local/bin +sudo service dpdk restart +sudo service openvswitch-switch restart +sudo ovs-vsctl add-br br-dpdk -- set bridge br-dpdk datapath_type=netdev +sudo modprobe uio_pci_generic +#sudo ip address flush enp0s9 +#sudo /usr/share/dpdk/tools/dpdk_nic_bind.py --bind=uio_pci_generic enp0s9 +#sudo ovs-vsctl add-port br-dpdk dpdk0 -- set Interface dpdk0 type=dpdk +while true; do sleep 3600; done +echo sudo docker run -ti --privileged -v /dev:/dev -v /usr/local/bin:/usr/local/bin -v /var/run/openvswitch/:/var/run/openvswitch/ dpdk /ovsdpdk/start.sh diff --git a/src/vagrant/k8s_kubeadm/worker_setup.sh b/src/vagrant/k8s_kubeadm/worker_setup.sh index a9c8336..b68d800 100644 --- a/src/vagrant/k8s_kubeadm/worker_setup.sh +++ b/src/vagrant/k8s_kubeadm/worker_setup.sh @@ -1,22 +1,4 @@ -#!/usr/bin/env bash +#!/bin/bash -set -e -HOME=`pwd` - -cat << EOF | sudo tee /etc/hosts -127.0.0.1 localhost -192.168.1.10 master -192.168.1.21 worker1 -192.168.1.22 worker2 -192.168.1.23 worker3 -EOF - -curl -s http://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add - -cat <