Skip to content

Commit

Permalink
Merge pull request #38 from QingCloudAppcenter/kubernetes-1.8.4
Browse files Browse the repository at this point in the history
Kubernetes 1.8.4
  • Loading branch information
calvinyv authored Dec 25, 2017
2 parents 21469ad + 88dbcaf commit 1db1b25
Show file tree
Hide file tree
Showing 101 changed files with 2,620 additions and 159 deletions.
1 change: 1 addition & 0 deletions ansible/build_images.retry
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
172.16.2.2
11 changes: 11 additions & 0 deletions ansible/build_images.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
- name: build Kubernetese images
hosts: all
remote_user: root
roles:
- base
- docker
- qingcloudagent
- salt
- kubernetes
- kubernetes_addon
1 change: 1 addition & 0 deletions ansible/group_vars/all
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
kubernetes_version: v1.8.4
2 changes: 2 additions & 0 deletions ansible/inventories/hosts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[kubernetes]
172.16.2.2
5 changes: 5 additions & 0 deletions ansible/roles/base/files/interfaces
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
auto lo
iface lo inet loopback

allow-hotplug eth0
iface eth0 inet dhcp
2 changes: 2 additions & 0 deletions ansible/roles/base/files/logrotate
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
logrotate /etc/logrotate.conf
3 changes: 3 additions & 0 deletions ansible/roles/base/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
- name: restart ntpd
service: name=ntp state=restarted
27 changes: 27 additions & 0 deletions ansible/roles/base/tasks/debian.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
- name: upgrade Debian family
apt:
upgrade: dist

- name: install utilities
apt:
name: "{{item}}"
state: latest
with_items:
- ebtables
- socat
- jq
- apt-transport-https
- ca-certificates
- curl
- software-properties-common
- bash-completion
- ntp
- wget
- logrotate
- python-pip
notify:
- restart ntpd
- name: remove networkmanager
apt:
name: network-manager
state: absent
52 changes: 52 additions & 0 deletions ansible/roles/base/tasks/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
- name: setup Ubuntu image
include_tasks: debian.yaml
when: ansible_os_family == 'Debian'


- name: setup Centos images
include_tasks: redhat.yaml
when: ansible_os_family == 'RedHat'

- name: setup logrotate
copy:
src: files/{{item}}
dest: /etc/cron.hourly/{{item}}
owner: root
group: root
mode: 0644
backup: yes
with_items:
- logrotate

- name: setup sysctl
sysctl:
name: "{{item.name}}"
state: present
value: "{{item.value }}"
sysctl_set: yes
reload: yes
with_items:
- { "name": "net.ipv4.ip_forward", "value": 1 }
- { "name": "vm.swappiness", "value": 1}
- { "name": "net.ipv4.conf.all.rp_filter", "value": 2}
- { "name": "vm.max_map_count", "value": 262144 }
- { "name": "fs.file-max", "value": 200000 }
- { "name": "fs.inotify.max_user_watches", "value": 1048576}
- { "name": "fs.inotify.max_user_instances", "value": 2048}

- name: setup default nic
copy:
src: files/{{item}}
dest: /etc/network/{{item}}
owner: root
group: root
mode: 0644
backup: yes
with_items:
- interfaces

- name: set timezone to UTC
timezone:
name: UTC
notify:
- restart ntpd
63 changes: 63 additions & 0 deletions ansible/roles/base/tasks/redhat.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
- name: install essential pkgs
become: yes
become_user: root
with_items:
- epel-release
yum:
name: '{{item}}'
state: present

- name: install repo tool
become: yes
become_user: root
with_items:
- yum-plugin-fastestmirror
yum:
name: '{{item}}'
state: latest

- name: Enable apply fastest mirror
ini_file:
path: /etc/yum/pluginconf.d/fastestmirror.conf
section: main
option: enabled
value: 1
backup: yes

- name: upgrade all packages
yum:
name: '*'
state: latest

- name: install utils pkgs
become: yes
become_user: root
with_items:
- yum-updateonboot
- yum-cron
- yum-plugin-fastestmirror
- ntp
- bash
- openssl
yum:
name: '{{item}}'
state: latest

- name: Enable apply updated packages
ini_file:
path: /etc/yum/yum-cron.conf
section: commands
option: apply_updates
value: yes
backup: yes

- name: enable services
become: yes
become_user: root
with_items:
- yum-updateonboot
- yum-cron
- ntpd
service:
name: '{{item}}'
enabled: yes
3 changes: 3 additions & 0 deletions ansible/roles/docker/files/daemon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"storage-driver": "overlay2"
}
10 changes: 10 additions & 0 deletions ansible/roles/docker/files/docker-containers
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/data/var/lib/docker/containers/*/*-json.log {
rotate 1
copytruncate
missingok
notifempty
compress
maxsize 10M
daily
create 0644 root root
}
3 changes: 3 additions & 0 deletions ansible/roles/docker/handlers/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- name: restart docker
service: name=docker state=restarted

28 changes: 28 additions & 0 deletions ansible/roles/docker/tasks/debian.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
- name: remove old version of docker
apt:
name: "{{item}}"
state: absent
with_items:
- docker
- docker-engine
- docker.io

- name: install docker repo key
apt_key:
url: https://download.docker.com/linux/ubuntu/gpg
id: 0EBFCD88
state: present

- name: install docker repo
apt_repository:
repo: deb https://download.docker.com/linux/ubuntu {{ansible_lsb.codename}} stable
update_cache: true

- name: install docker
apt:
name: "{{item}}"
state: latest
with_items:
- docker-ce
notify:
- restart docker
53 changes: 53 additions & 0 deletions ansible/roles/docker/tasks/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
- name: setup Ubuntu image
include_tasks: debian.yaml
when: ansible_os_family == 'Debian'


- name: setup Centos images
include_tasks: redhat.yaml
when: ansible_os_family == 'RedHat'

- name: setup docker python client
pip:
name: docker-py

- name: enable docker
service:
name: docker
enabled: yes

- name: setup logrotate
copy:
src: files/{{item}}
dest: /etc/logrotate.d/{{item}}
owner: root
group: root
mode: 0644
backup: yes
with_items:
- docker-containers

- name: docker login
docker_login:
username: guest
password: guest
registry_url: https://dockerhub.qingcloud.com
state: present

- name: setup storage driver
copy:
src: files/{{item}}
dest: /etc/docker/{{item}}
owner: root
group: root
mode: 0644
backup: yes
with_items:
- daemon.json
notify:
- restart docker

- name: enable service def
systemd:
name: docker
enabled: yes
Empty file.
36 changes: 36 additions & 0 deletions ansible/roles/kubernetes/files/kubelet.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
[Unit]
Description=Kubernetes Kubelet Server
Documentation=https://github.com/GoogleCloudPlatform/kubernetes
After=docker.service
Requires=docker.service

[Service]
WorkingDirectory=/data/var/lib/kubelet
EnvironmentFile=-/etc/kubernetes/kubelet
ExecStart=/usr/bin/kubelet \
$KUBE_LOGTOSTDERR \
$KUBE_LOG_LEVEL \
$KUBE_ALLOW_PRIV \
$KUBELET_ADDRESS \
$KUBELET_PORT \
$KUBELET_HOSTNAME \
$KUBELET_NETWORK_ARGS \
$KUBELET_SYSTEM_PODS_ARGS \
$KUBELET_KUBECONFIG_ARGS \
$KUBELET_DNS_ARGS \
$KUBE_CLOUD_PROVIDER \
$KUBELET_AUTHZ_ARGS \
$KUBELET_CGROUP_ARGS \
$KUBELET_EXTRA_ARGS \
$KUBELET_FLAGS \
Restart=on-failure
KillMode=process

[Install]
WantedBy=multi-user.target






3 changes: 3 additions & 0 deletions ansible/roles/kubernetes/tasks/debian.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
- name: config kubernetes repo

47 changes: 47 additions & 0 deletions ansible/roles/kubernetes/tasks/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@

- name: download kubernetes repo
get_url:
url: https://pek3a.qingstor.com/k8s-qingcloud/k8s/{{ kubernetes_version }}/bin/{{item}}
dest: /usr/bin/{{item}}
mode: 755
with_items:
- kubelet
- kubectl
- kubeadm

- name: install shell completion
shell: |
kubectl completion bash >/etc/profile.d/kubectl.sh
kubeadm completion bash >/etc/profile.d/kubeadm.sh
- name: install kubelet systemd def
copy:
src: files/{{item}}
dest: /etc/systemd/system/{{item}}
owner: root
group: root
mode: 0644
backup: yes
with_items:
- kubelet.service

- name: load service def
systemd:
daemon_reload: yes
name: kubelet
enabled: yes

- name: pull docker images
docker_image:
name: dockerhub.qingcloud.com/google_containers/{{item.name}}:{{item.version}}
state: present
with_items:
- { name: "hyperkube-amd64", version: "{{kubernetes_version}}" }
- { name: "etcd-amd64", version: "3.0.17" }
- { name: "pause-amd64:3.0", version: "3.0"}
- { name: "k8s-dns-kube-dns-amd64", version: "1.14.5"}
- { name: "k8s-dns-dnsmasq-nanny-amd64", version: "1.14.5"}
- { name: "k8s-dns-sidecar-amd64", version: "1.14.5"}
- { name: "kube-addon-manager:", version: "v6.4-beta.2"}
- { name: "addon-resizer", version: "1.7"}

Empty file.
2 changes: 2 additions & 0 deletions ansible/roles/kubernetes/vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
kubernetes_version: v1.8.4
9 changes: 9 additions & 0 deletions ansible/roles/kubernetes_addon/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
- name: download docker images
docker_image:
name: dockerhub.qingcloud.com/{{item.repo}}/{{ item.name }}:{{item.version}}
state: present
with_items:
- { repo: "google_containers", name: "heapster-amd64", version: "v1.4.3"}
- { repo: "google_containers", name: "kibana", version: "v5.4.0"}
- { repo: "google_containers", name: "elasticsearch", version: "v5.5.1-1"}
- { repo: "google_containers", name: "kubernetes-dashboard-amd64",version: "v1.8.0"}
Loading

0 comments on commit 1db1b25

Please sign in to comment.