Skip to content

Instantly share code, notes, and snippets.

@georgepaoli
Last active December 21, 2018 16:39
Show Gist options
  • Save georgepaoli/1a66e74e3bc13eff84e6ac3e92e52278 to your computer and use it in GitHub Desktop.
Save georgepaoli/1a66e74e3bc13eff84e6ac3e92e52278 to your computer and use it in GitHub Desktop.
Create k8s Cluster

Minimum requeriments

https://kubernetes.io/docs/setup/independent/install-kubeadm/#before-you-begin

Install docker 18.06 (version tested by k8s)

https://docs.docker.com/install/linux/docker-ce/ubuntu/#install-docker-ce

sudo su
apt-get update && apt-get install -y apt-transport-https ca-certificates curl software-properties-common    
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
add-apt-repository "deb https://download.docker.com/linux/$(. /etc/os-release; echo "$ID") $(lsb_release -cs) stable"
apt-get update && apt-get install -y docker-ce=$(apt-cache madison docker-ce | grep 18.06 | head -1 | awk '{print $3}')

Install kubeadm, kubelet and kubectl for setup cluster

https://kubernetes.io/docs/setup/independent/install-kubeadm/#installing-kubeadm-kubelet-and-kubectl

sudo su
apt-get update && apt-get install -y apt-transport-https curl
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

Initializing master

https://kubernetes.io/docs/setup/independent/create-cluster-kubeadm/#initializing-your-master

CIDR (range of IP addresses) recommended for Calico

sudo kubeadm init --pod-network-cidr=192.168.0.0/16

CIDR (range of IP addresses) recommended for Flannel

sudo kubeadm init --pod-network-cidr=10.244.0.0/16

Result:

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.128.0.2:6443 --token rj9rin.yweqp7dz3s8ylymn --discovery-token-ca-cert-hash sha256:4eb33f0f6df936466a500f2a8e3f85200b8a944bd99325244a999222f638a5db

Install Calico Network CNI (if need security)

https://docs.projectcalico.org/v3.4/getting-started/kubernetes/

kubectl apply -f https://docs.projectcalico.org/v3.4/getting-started/kubernetes/installation/hosted/etcd.yaml
kubectl apply -f https://docs.projectcalico.org/v3.4/getting-started/kubernetes/installation/hosted/calico.yaml

Note: simple policy tutorial fail. communication pod-to-pod not works. https://docs.projectcalico.org/v3.4/getting-started/kubernetes/tutorials/simple-policy


Install Flannel Network CNI (don't need security)

https://kubernetes.io/docs/setup/independent/create-cluster-kubeadm/#pod-network

sudo sysctl net.bridge.bridge-nf-call-iptables=1
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/bc79dd1505b0c8681ece4de4c0d86c5cd2643275/Documentation/kube-flannel.yml

Note: simple policy tutorial of calico works fine!


Set node role

https://stackoverflow.com/a/51563019/2076784

kubectl label node NODE_NAME node-role.kubernetes.io/worker=worker

Others refs:

https://churrops.io/2018/06/19/kubernetes-criando-um-cluster-simples-em-cloud-com-o-kubeadm/ https://itnext.io/benchmark-results-of-kubernetes-network-plugins-cni-over-10gbit-s-network-36475925a560

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment