Setup a Kubernetes Cluster in 20 minutes

Kubernetes 3 Node Cluster

OS Used for Kubernetes Setup

  • Ubuntu 18.04.2 LTS (GNU/Linux 4.15.0–48-generic x86_64)

Software Required

  • ansible>=2.7.8
  • jinja2>=2.9.6
  • kubeadmin
  • kubespray
  • Python

Switching off swap

$ swapoff -a

Adding RSA Keys

$ sudo su
$ ssh-keygen
$ vim ~/.ssh/authorized_keys

Installing Kubespray on Host Machine

$ git clone https://github.com/kubernetes-sigs/kubespray
$ cd kubespray
$ sudo pip install -r requirements.txt
$ cp -rfp inventory/sample inventory/mycluster
$ declare -a IPS=(10.10.1.10 10.10.1.11 10.10.1.12)
$ CONFIG_FILE=inventory/mycluster/hosts.yml python3 contrib/inventory_builder/inventory.py ${IPS[@]}
$ rm -rf inventory/mycluster/hosts.ini
$ vim inventory/mycluster/hosts.ini
[all]
kubernetes-node1 ansible_host=10.0.10.10 ip=10.0.10.10 ansible_user=root
kubernetes-node2 ansible_host=10.0.10.11 ip=10.0.10.11 ansible_user=root
kubernetes-node3 ansible_host=10.0.10.12 ip=10.0.10.12 ansible_user=root
[kube-master]
kubernetes-node1
[etcd]
kubernetes-node1
kubernetes-node2
kubernetes-node3
[kube-node]
kubernetes-node1
kubernetes-node2
kubernetes-node3
[k8s-cluster:children]
kube-master
kube-node
[calico-rr]

Helm Installation (Optional)

$ vim inventory/mycluster/group_vars/k8s-cluster/k8s-cluster.ymlhelm_enabled: true
helm_version: "v2.13.1"
$ ansible-playbook -i inventory/mycluster/hosts.ini --become --become-user=root cluster.yml --flush-cache
Installation Complete

Kubernetes Nodes Information

$  kubectl get nodes

Kubernetes Cluster Information

$  kubectl cluster-info
Kubernetes master is running at https://10.0.10.10:6443
coredns is running at https://10.0.10.10:6443/api/v1/namespaces/kube-system/services/coredns:dns/proxy
kubernetes-dashboard is running at https://10.0.10.10:6443/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy
To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.

Applying Admin configuration to all pods

$ cp /etc/kubernetes/admin.conf .
$ kubectl --kubeconfig=admin.conf get pods --all-namespaces
Pods Running

Kubernetes Dashboard

$ vim kubernetes-dashboard.yml
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
name: kubernetes-dashboard
labels:
k8s-app: kubernetes-dashboard
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
subjects:
- kind: ServiceAccount
name: kubernetes-dashboard
namespace: kube-system
$ kubectl apply -f kubernetes-dashboard.yml
$ kubectl describe secret -n kube-system $(kubectl get secrets -n kube-system | grep dashboard-token | cut -d ‘ ‘ -f1) | grep -E ‘^token’ | cut -f2 -d’:’ | tr -d ‘\t’
kubernetes-dashboard

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Privilege Escalation by JWT Token Manipulation

Introduction to Timeline in Unity

Testing with Threads

C++ Primer should not be recommended for a beginner

Algorithms

Fun with Skybox’s in Unity!

Strata Data Conference — SF 2019

Native apps, hybrid apps, webview? What is the preferred approach?

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Alien

Alien

More from Medium

An Introduction to Kubernetes

Learn Kubernetes: Ingress — Use Ingress

How to Convert Helm Chart to Kubernetes YAML

Kubernetes