Skip to content

Instantly share code, notes, and snippets.

@fktkrt
Last active October 9, 2019 08:03
Show Gist options
  • Save fktkrt/3d2fc757a5364b8c9e31d16092f167d6 to your computer and use it in GitHub Desktop.
Save fktkrt/3d2fc757a5364b8c9e31d16092f167d6 to your computer and use it in GitHub Desktop.
Setting up a k8s cluster on vmware vsphere

i. Prerequisites

  • docker

As root, execute the following commands:

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
apt-get update

Install kubectl, kubelt and kubeadm packages

apt install -y kubectl kubelet kubeadm

Disable swap by

swapoff -a

and in /etc/fstab comment out the swap line, as seen below:

# swap was on /dev/sda5 during installation
#UUID=c7a1e6fa-3444-4c4d-9d46-29a0448abcff none            swap    sw              0       0

Initialize your cluster by

kubeadm init

You should see a similar output

...
...
...
[bootstrap-token] Creating the "cluster-info" ConfigMap in the "kube-public" namespace
[addons] Applied essential addon: CoreDNS
[addons] Applied essential addon: kube-proxy

Your Kubernetes control-plane 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/

Then you can join any number of worker nodes by running the following on each as root:

kubeadm join <YOUR-IP>:6443 --token 5wbsg1.mutelqy5t1xuswm3 \
    --discovery-token-ca-cert-hash sha256:53fcac3142d4224ea4e5909a76f0706b0ce671b5d00e7c97062edccba064c3bc

If you check the setup at this phase by

kubectl get nodes

You will notice the following message:

error: the server doesn't have a resource type "nodes"

Configure the master node with the aforementioned commands:

mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

Check again

root@docker:~# kubectl get nodes
NAME     STATUS     ROLES    AGE    VERSION
docker   NotReady   master   2m3s   v1.15.2

You can see the node is NotReady, that's because the cluster networking isn't configured yet, we can do this with:

kubectl apply -f https://git.io/weave-kube-1.6
serviceaccount/weave-net created
clusterrole.rbac.authorization.k8s.io/weave-net created
clusterrolebinding.rbac.authorization.k8s.io/weave-net created
role.rbac.authorization.k8s.io/weave-net created
rolebinding.rbac.authorization.k8s.io/weave-net created
daemonset.extensions/weave-net created

After this, you can join other nodes to the cluster

root@docker:~# kubectl get nodes
NAME     STATUS   ROLES    AGE   VERSION
docker   Ready    master   22m   v1.15.2

You can check the configured cluster info by:

kubectl cluster-info
Kubernetes master is running at https://<YOUR-IP>:6443
KubeDNS is running at https://<YOUR-IP>:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment