Wednesday, November 29, 2017

How to quick setup kubernetes dev box on ubuntu.

This post shows you how to setup KAIO ( kubernete all in one ) dev box on your VirtualBox ubuntu 1604.

1. Prepare vagrant file - Vagrantfile

$ cat Vagrantfile
Vagrant.configure(2) do |config|
  config.vm.define "ss03" do |ss03|
    ss03.vm.box = "ubuntu/xenial64"
    ss03.vm.box_version = "20171011.0.0"
    ss03.ssh.insert_key = 'false'
    ss03.vm.hostname = "ss03.swiftstack.idv"
    ss03.vm.network "private_network", ip: "172.28.128.43", name: "vboxnet0"
    ss03.vm.provider :virtualbox do |vb|
        vb.memory = 4096
        vb.cpus = 2
    end
  end
end

$ vagrant up

$ vagrant ssh ss03


2. Prepare k8s setup file - k8s.sh

$ cat k8s.sh

sudo apt-get update -y && apt-get install -y apt-transport-https
sudo apt install docker.io -y
sudo systemctl start docker
sudo systemctl enable docker
sudo apt install python-swiftclient -y
echo "================================="
sudo curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add
echo "deb http://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee -a /etc/apt/sources.list.d/kubernetes.list
sudo apt-get update -y
sudo apt-get install -y kubelet kubeadm kubectl kubernetes-cni
sudo kubeadm init
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
kubectl taint nodes --all node-role.kubernetes.io/master-
kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')"
kubectl get pods --all-namespaces

kubectl get nodes

PS: if you don't know how to prepare k8s.sh

vi k8s.sh
copy above w/o "$ cat k8s.sh" and paste.
wq or x save and exit

$ sudo chmod +x k8s.sh

$ sudo ./k8s.sh


That's it!

you might need to wait a while to let all k8s spin up properly.

then you should able to see this.


$ sudo kubectl get pods --all-namespaces
NAMESPACE     NAME                           READY     STATUS    RESTARTS   AGE
kube-system   etcd-ss03                      1/1       Running   0          1m
kube-system   kube-apiserver-ss03            1/1       Running   0          40s
kube-system   kube-controller-manager-ss03   1/1       Running   0          1m
kube-system   kube-dns-545bc4bfd4-h722h      3/3       Running   0          1m
kube-system   kube-proxy-m7m6q               1/1       Running   0          1m
kube-system   kube-scheduler-ss03            1/1       Running   0          31s
kube-system   weave-net-jlqx9                2/2       Running   0          1m

$ sudo kubectl get nodes
NAME      STATUS    ROLES     AGE       VERSION
ss03      Ready     master    1m        v1.8.4


Reference:
https://github.com/chianingwang/KAIO/tree/master



No comments:

Post a Comment