• Stars
    star
    718
  • Rank 63,070 (Top 2 %)
  • Language Jinja
  • License
    Apache License 2.0
  • Created over 7 years ago
  • Updated 6 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Build a Kubernetes cluster using kubeadm via Ansible.

Kubeadm Ansible Playbook

Build a Kubernetes cluster using Ansible with kubeadm. The goal is easily install a Kubernetes cluster on machines running:

  • Ubuntu 16.04
  • CentOS 7
  • Debian 9

System requirements:

  • Deployment environment must have Ansible 2.4.0+
  • Master and nodes must have passwordless SSH access

Usage

Add the system information gathered above into a file called hosts.ini. For example:

[master]
192.16.35.12

[node]
192.16.35.[10:11]

[kube-cluster:children]
master
node

If you're working with ubuntu, add the following properties to each host ansible_python_interpreter='python3':

[master]
192.16.35.12 ansible_python_interpreter='python3'

[node]
192.16.35.[10:11] ansible_python_interpreter='python3'

[kube-cluster:children]
master
node

Before continuing, edit group_vars/all.yml to your specified configuration.

For example, I choose to run flannel instead of calico, and thus:

# Network implementation('flannel', 'calico')
network: flannel

Note: Depending on your setup, you may need to modify cni_opts to an available network interface. By default, kubeadm-ansible uses eth1. Your default interface may be eth0.

After going through the setup, run the site.yaml playbook:

$ ansible-playbook site.yaml
...
==> master1: TASK [addon : Create Kubernetes dashboard deployment] **************************
==> master1: changed: [192.16.35.12 -> 192.16.35.12]
==> master1:
==> master1: PLAY RECAP *********************************************************************
==> master1: 192.16.35.10               : ok=18   changed=14   unreachable=0    failed=0
==> master1: 192.16.35.11               : ok=18   changed=14   unreachable=0    failed=0
==> master1: 192.16.35.12               : ok=34   changed=29   unreachable=0    failed=0

The playbook will download /etc/kubernetes/admin.conf file to $HOME/admin.conf.

If it doesn't work download the admin.conf from the master node:

$ scp k8s@k8s-master:/etc/kubernetes/admin.conf .

Verify cluster is fully running using kubectl:

$ export KUBECONFIG=~/admin.conf
$ kubectl get node
NAME      STATUS    AGE       VERSION
master1   Ready     22m       v1.6.3
node1     Ready     20m       v1.6.3
node2     Ready     20m       v1.6.3

$ kubectl get po -n kube-system
NAME                                    READY     STATUS    RESTARTS   AGE
etcd-master1                            1/1       Running   0          23m
...

Resetting the environment

Finally, reset all kubeadm installed state using reset-site.yaml playbook:

$ ansible-playbook reset-site.yaml

Additional features

These are features that you could want to install to make your life easier.

Enable/disable these features in group_vars/all.yml (all disabled by default):

# Additional feature to install
additional_features:
  helm: false
  metallb: false
  healthcheck: false

Helm

This will install helm in your cluster (https://helm.sh/) so you can deploy charts.

MetalLB

This will install MetalLB (https://metallb.universe.tf/), very useful if you deploy the cluster locally and you need a load balancer to access the services.

Healthcheck

This will install k8s-healthcheck (https://github.com/emrekenci/k8s-healthcheck), a small application to report cluster status.

Utils

Collection of scripts/utilities

Vagrantfile

This Vagrantfile is taken from https://github.com/ecomm-integration-ballerina/kubernetes-cluster and slightly modified to copy ssh keys inside the cluster (install https://github.com/dotless-de/vagrant-vbguest is highly recommended)

Tips & Tricks

Specify user for Ansible

If you use vagrant or your remote user is root, add this to hosts.ini

[master]
192.16.35.12 ansible_user='root'

[node]
192.16.35.[10:11] ansible_user='root'

Access Kubernetes Dashboard

As of release 1.7 Dashboard no longer has full admin privileges granted by default, so you need to create a token to access the resources:

$ kubectl -n kube-system create sa dashboard
$ kubectl create clusterrolebinding dashboard --clusterrole cluster-admin --serviceaccount=kube-system:dashboard
$ kubectl -n kube-system get sa dashboard -o yaml
apiVersion: v1
kind: ServiceAccount
metadata:
  creationTimestamp: 2017-11-27T17:06:41Z
  name: dashboard
  namespace: kube-system
  resourceVersion: "69076"
  selfLink: /api/v1/namespaces/kube-system/serviceaccounts/dashboard
  uid: 56b880bf-d395-11e7-9528-448a5ba4bd34
secrets:
- name: dashboard-token-vg52j

$ kubectl -n kube-system describe secrets dashboard-token-vg52j
...
token:      eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlLXN5c3RlbSIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJkYXNoYm9hcmQtdG9rZW4tdmc1MmoiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC5uYW1lIjoiZGFzaGJvYXJkIiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQudWlkIjoiNTZiODgwYmYtZDM5NS0xMWU3LTk1MjgtNDQ4YTViYTRiZDM0Iiwic3ViIjoic3lzdGVtOnNlcnZpY2VhY2NvdW50Omt1YmUtc3lzdGVtOmRhc2hib2FyZCJ9.bVRECfNS4NDmWAFWxGbAi1n9SfQ-TMNafPtF70pbp9Kun9RbC3BNR5NjTEuKjwt8nqZ6k3r09UKJ4dpo2lHtr2RTNAfEsoEGtoMlW8X9lg70ccPB0M1KJiz3c7-gpDUaQRIMNwz42db7Q1dN7HLieD6I4lFsHgk9NPUIVKqJ0p6PNTp99pBwvpvnKX72NIiIvgRwC2cnFr3R6WdUEsuVfuWGdF-jXyc6lS7_kOiXp2yh6Ym_YYIr3SsjYK7XUIPHrBqWjF-KXO_AL3J8J_UebtWSGomYvuXXbbAUefbOK4qopqQ6FzRXQs00KrKa8sfqrKMm_x71Kyqq6RbFECsHPA

$ kubectl proxy

Copy and paste the token from above to dashboard.

Login the dashboard:

More Repositories

1

kube-ansible

Build a Kubernetes cluster via Ansible playbook. πŸ”§ πŸ”§ πŸ”§
HTML
437
star
2

learning-blockchain

Tidy up Blockchain ecosystem and tutorial
207
star
3

kubereum

Kubernetes + Ethereum = Kubereum!!!
Python
88
star
4

learning-ceph

Tidy up Ceph tutorials.
Shell
44
star
5

openstack-handbook

OpenStack Technical Cook Book
HTML
30
star
6

k8s-manual-files

A collection of files for deploying Kubernetes the hard way .
Shell
29
star
7

learning-spark

Tidy up Spark and Hadoop tutorials.
Java
27
star
8

aws-k8s-federation

Setup Kubernetes Federation v2 on AWS.
Shell
27
star
9

pod-websocket-exec

Learning how to exec a pod via WebSocket written in Go.
Go
26
star
10

cloud-of-mosquitto

Mosquitto MQTT Broker on Kubernetes
Python
23
star
11

kubectl-config-merge

A kubectl plugin for merging multiple kubeconfig files. A cli-runtime example.
Go
23
star
12

workshop413

Kubernetes + TensorFlow Workshop
20
star
13

kourse

A collection of container tutorials that gets you on-boarded to CONTAINER WORLD!
C
20
star
14

kairen.github.io

KaiRen's blog. The archived blog: https://kairen-archived.github.io
HTML
17
star
15

maas-wakeonlan-driver

Patch the WoL Driver in MAAS 2.2+
Python
17
star
16

controller101

An example of Kubernetes custom controller that shows you how to manage VMs.
Go
14
star
17

client-go-examples

A collection of example for learning how to use Golang.
Go
14
star
18

docker-training

Tidy up Docker ecosystem tutorial
Shell
13
star
19

k8s-ddns

Deploy Kubernetes ExternalDNS for CoreDNS.
13
star
20

ironic-k8s

Deploy Kubernetes Using OpenStack Ironic
Shell
11
star
21

kubeconfig-generator

Kubeconfig Generator is a tool to generate kubeconfig.
Go
11
star
22

kube-s3-portal

Containerize S3 Portal.
Shell
11
star
23

kube-ldap-webhook

Kubernetes LDAP authentication service written in Go.
Go
10
star
24

k8s-ceph-examples

Kubernetes and Ceph Integration demo.
Shell
8
star
25

k8s-apps

A collection of example for running on Kubernetes.
Shell
6
star
26

openstack-ubuntu

OpenStack Ubuntu Install Guide
5
star
27

ceph-doc-taiwan

Ceph documentation for zh-tw.
C++
5
star
28

simple-device-plugin

A simple Kubernetes device plugin.
Go
5
star
29

line-bot-operator

An operator deploys/manages/configures LINE bot atop Kubernetes.
Go
5
star
30

vault-labs

Labs for demonstrating Hasicorp Vault + Kubernetes(or OCP).
Shell
5
star
31

ceph-bench-history

My Ceph Benchmark history files.
Shell
4
star
32

r-data-mining

Data mining example for R Language.
R
4
star
33

spark-ceph-example

Learning how to integrate Ceph S3 with Spark.
Shell
4
star
34

EHC-2015-contest

Etu Hadoop Competition contest code.
Java
4
star
35

ansible-labs

Ansible and Ansible Tower Labs for the customer training course
Jinja
2
star
36

iot-demo

A simple codes for demonstrating IoT on my office.
Shell
2
star
37

openshift-pipeline-labs

OpenShift Pipeline examples for a workshop.
Shell
2
star
38

mqtt-benchmark

MQTT Benchmark for python
Python
2
star
39

ironman-2021

2020 ithelp ironman record. Terraform + Terragrunt + CDK 30 days
2
star
40

fuel-calamari-installer

Shell
2
star
41

rpi-collector

Collect sensor data using Raspberry Pi, and publish data to MQTT, Kafka server
Python
1
star
42

github-bot

@kairen-bot to handle GitHub and GitLab workflow.
Go
1
star
43

not-docker-monitor

Example collect meters from Docker
Python
1
star
44

operator101

An example that shows you how to develop and bootstrap a Kubernetes operator.
1
star
45

ceph-client-ios

Ceph client for Ceph REST API
Objective-C
1
star
46

ironman-2019

2019 ithelp ironman record.
1
star
47

vm-controller

A sample controller to manage/operate VM atop Kubernetes
Go
1
star
48

dockerfiles

Various Dockerfiles I use for developing and testing.
Scala
1
star
49

keepalived-ansible

Simple ansible playbook for keepalived.
1
star
50

dns-system

A collection of the file to deploy the DNS system top on Kubernetes. 🐧🐧🐧
Shell
1
star
51

eset-phonic-ios

ESET Phonic client for iOS
Objective-C
1
star