Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
tennix committed Jan 23, 2017
0 parents commit 0a05733
Show file tree
Hide file tree
Showing 80 changed files with 1,973 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*.tar
*.tar.gz
retry_files/
fact_files/
.vagrant/
tmp/
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
ansible, python-netaddr on control machine

# Deploy k8s cluster
modify inventory/hosts and inventory/group_vars/all.yml

deploy all components
```
ansible-playbook deploy-cluster.yml
```

or one by one

```
ansible-playbook prepare.yml
ansible-playbook deploy-etcd.yml
ansible-playbook deploy-master.yml
ansible-playbook deploy-node.yml
ansible-playbook deploy-addons.yml
```

To add more nodes after cluster is up and running, just add new nodes to inventory/hosts and run
```
ansible-playbook prepare.yml
ansible-playbook deploy-node.yml
```
31 changes: 31 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/trusty64"
config.vm.box_check_update = false

config.vm.define "kube-master" do |s|
s.vm.network "private_network", ip: "10.7.0.10"
s.vm.network "forwarded_port", guest: 80, host: 18080
s.vm.hostname = "kube-master"
s.vm.provider "virtualbox" do |v|
v.name = "kube-master"
v.memory = 2048
v.cpus = 1
end
end

(1..2).each do |n|
config.vm.define "kube-node#{n}" do |s|
s.vm.network "private_network", ip: "10.7.0.1#{n}"
s.vm.hostname = "kube-node#{n}"
s.vm.provider "virtualbox" do |v|
v.name = "kube-node#{n}"
v.memory = 2048
v.cpus = 1
end
end
end

end
12 changes: 12 additions & 0 deletions ansible.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[defaults]
roles_path = roles
inventory = inventory.ini
transport = ssh
host_key_checking = False

gathering = explicit
fact_caching = jsonfile
fact_caching_connection = fact_files
retry_files_save_path = retry_files

timeout = 10
8 changes: 8 additions & 0 deletions deploy-addons.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
- name: Deploy kubernetes addons
hosts: masters
become: yes
roles:
- addons
tags:
- addons
10 changes: 10 additions & 0 deletions deploy-cluster.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
- include: prepare.yml

- include: deploy-etcd.yml

- include: deploy-master.yml

- include: deploy-node.yml

- include: deploy-addons.yml
8 changes: 8 additions & 0 deletions deploy-etcd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
- name: Deploy etcd
hosts: etcd
become: yes
roles:
- etcd
tags:
- etcd
8 changes: 8 additions & 0 deletions deploy-master.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
- name: Deploy master
hosts: masters
become: yes
roles:
- master
tags:
- masters
9 changes: 9 additions & 0 deletions deploy-node.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
- name: Deploy node
hosts: nodes
become: yes
roles:
- node
# serial: 3
tags:
- nodes
17 changes: 17 additions & 0 deletions group_vars/all.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
cluster_name: cluster.local
kube_master_ip: 10.7.0.10
kube_service_cidr: 10.254.0.0/16
calico_ippool_cidr: 172.16.0.0/16
concurrent_node: 3 # deploy node concurrency

essentials_installed: false # essential packages(docker,nsenter,socat...) installed
net_install: false
all_in_one: false

public_iface: eth1 # for vagrant change this to eth1

# kube-addons
kube_ui: false
cluster_logging: false
cluster_monitoring: false
kube_network_policy: false
9 changes: 9 additions & 0 deletions inventory.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[etcd]
10.7.0.10

[masters]
10.7.0.10

[nodes]
10.7.0.11
10.7.0.12
14 changes: 14 additions & 0 deletions prepare.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
- name: Prepare binaries on local machine
hosts: localhost
connection: local
become: false
gather_facts: false
roles:
- local

- name: Prepare binaries on remote machines
hosts: all
become: true
roles:
- remote
3 changes: 3 additions & 0 deletions roles/addons/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
dependencies:
- { role: common }
41 changes: 41 additions & 0 deletions roles/addons/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
- name: Ensure addons directory exist
file: path={{ item }} state=directory mode=0755
with_items:
- /etc/kubernetes/addons/dns
- /etc/kubernetes/addons/dashboard
- /etc/kubernetes/addons/logging
- /etc/kubernetes/addons/monitoring

- name: Install kubedns
template: src="dns/{{ item }}.yaml.j2" dest="/etc/kubernetes/addons/dns/{{ item }}.yaml" mode=0644
with_items:
- skydns-rc
- skydns-svc

- name: Install kubernetes dashboard
template: src="dashboard/{{ item }}.yaml.j2" dest="/etc/kubernetes/addons/dashboard/{{ item }}.yaml" mode=0644
with_items:
- dashboard-controller
- dashboard-service
when: kube_ui

- name: Install logging addons
template: src="logging/{{ item }}.yaml.j2" dest="/etc/kubernetes/addons/logging/{{ item }}.yaml" mode=0644
with_items:
- es-rc
- es-svc
- fluentd-ds
- kibana-rc
- kibana-svc
when: cluster_logging

- name: Install monitoring addons
template: src="monitoring/{{ item }}.yaml.j2" dest="/etc/kubernetes/addons/monitoring/{{ item }}.yaml" mode=0644
with_items:
- node-exporter-ds
- prometheus-rc
- prometheus-svc
- grafana-rc
- grafana-svc
when: cluster_monitoring
40 changes: 40 additions & 0 deletions roles/addons/templates/dashboard/dashboard-controller.yaml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# This file should be kept in sync with cluster/gce/coreos/kube-manifests/addons/dashboard/dashboard-controller.yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: kubernetes-dashboard
namespace: kube-system
labels:
k8s-app: kubernetes-dashboard
kubernetes.io/cluster-service: "true"
spec:
selector:
matchLabels:
k8s-app: kubernetes-dashboard
template:
metadata:
labels:
k8s-app: kubernetes-dashboard
annotations:
scheduler.alpha.kubernetes.io/critical-pod: ''
scheduler.alpha.kubernetes.io/tolerations: '[{"key":"CriticalAddonsOnly", "operator":"Exists"}]'
spec:
containers:
- name: kubernetes-dashboard
image: gcr.io/google_containers/kubernetes-dashboard-amd64:v{{ kubernetes_dashboard_version }}
resources:
# keep request = limit to keep this container in guaranteed class
limits:
cpu: 100m
memory: 50Mi
requests:
cpu: 100m
memory: 50Mi
ports:
- containerPort: 9090
livenessProbe:
httpGet:
path: /
port: 9090
initialDelaySeconds: 30
timeoutSeconds: 30
15 changes: 15 additions & 0 deletions roles/addons/templates/dashboard/dashboard-service.yaml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# This file should be kept in sync with cluster/gce/coreos/kube-manifests/addons/dashboard/dashboard-service.yaml
apiVersion: v1
kind: Service
metadata:
name: kubernetes-dashboard
namespace: kube-system
labels:
k8s-app: kubernetes-dashboard
kubernetes.io/cluster-service: "true"
spec:
selector:
k8s-app: kubernetes-dashboard
ports:
- port: 80
targetPort: 9090
Loading

0 comments on commit 0a05733

Please sign in to comment.