• Stars
    star
    436
  • Rank 96,709 (Top 2 %)
  • Language
    HTML
  • License
    Apache License 2.0
  • Created over 7 years ago
  • Updated about 3 years 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 via Ansible playbook. 🔧 🔧 🔧

Build Status

Kubernetes Ansible

A collection of playbooks for deploying/managing/upgrading a Kubernetes cluster onto machines, they are fully automated command to bring up a Kubernetes cluster on bare-metal or VMs.

asciicast

Feature list:

  • Support Kubernetes v1.10.0+.
  • Highly available Kubernetes cluster.
  • Full of the binaries installation.
  • Kubernetes addons:
    • Promethues Monitoring.
    • EFK Logging.
    • Metrics Server.
    • NGINX Ingress Controller.
    • Kubernetes Dashboard.
  • Support container network:
    • Calico.
    • Flannel.
  • Support container runtime:
    • Docker.
    • NVIDIA-Docker.(Require NVIDIA driver and CUDA 9.0+)
    • Containerd.
    • CRI-O.

Quick Start

In this section you will deploy a cluster via vagrant.

Prerequisites:

  • Ansible version: v2.5 (or newer).
  • Vagrant: >= 2.0.0.
  • VirtualBox: >= 5.0.0.
  • Mac OS X need to install sshpass tool.
$ brew install http://git.io/sshpass.rb

The getting started guide will use Vagrant with VirtualBox to deploy a Kubernetes cluster onto virtual machines. You can deploy the cluster with a single command:

$ ./hack/setup-vms
Cluster Size: 1 master, 2 worker.
  VM Size: 1 vCPU, 2048 MB
  VM Info: ubuntu16, virtualbox
  CNI binding iface: eth1
Start to deploy?(y):
  • You also can use sudo ./hack/setup-vms -p libvirt -i eth1 command to deploy the cluster onto KVM.

If you want to access API you need to create RBAC object define the permission of role. For example using cluster-admin role:

$ kubectl create clusterrolebinding open-api --clusterrole=cluster-admin --user=system:anonymous

Login the addon's 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

Copy and paste the token to dashboard.

Manual deployment

In this section you will manually deploy a cluster on your machines.

Prerequisites:

  • Ansible version: v2.5 (or newer).
  • Linux distributions: Ubuntu 16+/Debian/CentOS 7.x.
  • All Master/Node should have password-less access from deploy node.

For machine example:

IP Address Role CPU Memory
172.16.35.9 vip - -
172.16.35.10 k8s-m1 4 8G
172.16.35.11 k8s-n1 4 8G
172.16.35.12 k8s-n2 4 8G
172.16.35.13 k8s-n3 4 8G

Add the machine info gathered above into a file called inventory/hosts.ini. For inventory example:

[etcds]
k8s-m1
k8s-n[1:2]

[masters]
k8s-m1
k8s-n1

[nodes]
k8s-n[1:3]

[kube-cluster:children]
masters
nodes

Set the variables in group_vars/all.yml to reflect you need options. For example:

# overide kubernetes version(default: 1.10.6)
kube_version: 1.11.2

# container runtime, supported: docker, nvidia-docker, containerd.
container_runtime: docker

# container network, supported: calico, flannel.
cni_enable: true
container_network: calico
cni_iface: ''

# highly available variables
vip_interface: ''
vip_address: 172.16.35.9

# etcd variables
etcd_iface: ''

# kubernetes extra addons variables
enable_dashboard: true
enable_logging: false
enable_monitoring: false
enable_ingress: false
enable_metric_server: true

# monitoring grafana user/password
monitoring_grafana_user: "admin"
monitoring_grafana_password: "p@ssw0rd"

Deploy a Kubernetes cluster

If everything is ready, just run cluster.yml playbook to deploy the cluster:

$ ansible-playbook -i inventory/hosts.ini cluster.yml

And then run addons.yml to create addons:

$ ansible-playbook -i inventory/hosts.ini addons.yml

Verify cluster

Verify that you have deployed the cluster, check the cluster as following commands:

$ kubectl -n kube-system get po,svc

NAME                                 READY     STATUS    RESTARTS   AGE       IP             NODE
po/haproxy-master1                   1/1       Running   0          2h        172.16.35.10   k8s-m1
...

Reset cluster

Finally, if you want to clean the cluster and redeploy, you can reset the cluster by reset-cluster.yml playbook.:

$ ansible-playbook -i inventory/hosts.ini reset-cluster.yml

Contributing

Pull requests are always welcome!!! I am always thrilled to receive pull requests.

More Repositories

1

kubeadm-ansible

Build a Kubernetes cluster using kubeadm via Ansible.
Jinja
706
star
2

learning-blockchain

Tidy up Blockchain ecosystem and tutorial
207
star
3

kubereum

Kubernetes + Ethereum = Kubereum!!!
Python
87
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
28
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
22
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
16
star
16

controller101

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

docker-training

Tidy up Docker ecosystem tutorial
Shell
13
star
18

k8s-ddns

Deploy Kubernetes ExternalDNS for CoreDNS.
13
star
19

client-go-examples

A collection of example for learning how to use Golang.
Go
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

ironman-2021

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

mqtt-benchmark

MQTT Benchmark for python
Python
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

keepalived-ansible

Simple ansible playbook for keepalived.
1
star
47

ironman-2019

2019 ithelp ironman record.
1
star
48

vm-controller

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

dockerfiles

Various Dockerfiles I use for developing and testing.
Scala
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