Skip to content

Commit f41c0d0

Browse files
committed
Merge pull request kubernetes#10544 from eparis/total-ansible
Ansible improvements to support more addons and better cert/token handling
2 parents 96828f2 + ddf52a8 commit f41c0d0

File tree

21 files changed

+248
-168
lines changed

21 files changed

+248
-168
lines changed

contrib/ansible/group_vars/all.yml

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
# Only used for the location to store flannel info in etcd, but may be used
2-
# for dns purposes and cluster id purposes in the future.
3-
cluster_name: kube.local
1+
# will be used as the Internal dns domain name if DNS is enabled. Services
2+
# will be discoverable under <service-name>.<namespace>.svc.<domainname>, e.g.
3+
# myservice.default.svc.cluster.local
4+
cluster_name: cluster.local
45

56
# Account name of remote user. Ansible will use this user account to ssh into
67
# the managed machines. The user must be able to use sudo without asking
@@ -43,21 +44,17 @@ flannel_prefix: 12
4344
# room for 4096 nodes with 254 pods per node.
4445
flannel_host_prefix: 24
4546

47+
# Set to false to disable logging with elasticsearch
48+
cluster_logging: true
49+
50+
# Turn to false to disable cluster monitoring with heapster and influxdb
51+
cluster_monitoring: true
52+
4653
# Turn this varable to 'false' to disable whole DNS configuration.
4754
dns_setup: true
4855
# How many replicas in the Replication Controller
4956
dns_replicas: 1
5057

51-
# Internal DNS domain name.
52-
# This domain must not be used in your network. Services will be discoverable
53-
# under <service-name>.<namespace>.<domainname>, e.g.
54-
# myservice.default.kube.local
55-
dns_domain: kube.local
56-
57-
# IP address of the DNS server.
58-
# Kubernetes will create a pod with several containers, serving as the DNS
59-
# server and expose it under this IP address. The IP address must be from
60-
# the range specified as kube_service_addresses above.
61-
# And this is the IP address you should use as address of the DNS server
62-
# in your containers.
63-
dns_server: 10.254.0.10
58+
# There are other variable in roles/kubernetes/defaults/main.yml but changing
59+
# them comes with a much higher risk to your cluster. So proceed over there
60+
# with caution.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
- name: LOGGING | Assures {{ kube_config_dir }}/addons/cluster-logging dir exists
3+
file: path={{ kube_config_dir }}/addons/cluster-logging state=directory
4+
5+
- name: LOGGING | Download logging files from Kubernetes repo
6+
get_url:
7+
url=https://raw.githubusercontent.com/GoogleCloudPlatform/kubernetes/master/cluster/addons/fluentd-elasticsearch/{{ item }}
8+
dest="{{ kube_config_dir }}/addons/cluster-logging/"
9+
force=yes
10+
with_items:
11+
- es-controller.yaml
12+
- es-service.yaml
13+
- kibana-controller.yaml
14+
- kibana-service.yaml
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
- name: MONITORING | Assures {{ kube_config_dir }}/addons/cluster-monitoring dir exists
3+
file: path={{ kube_config_dir }}/addons/cluster-monitoring state=directory
4+
5+
- name: MONITORING | Download monitoring files from Kubernetes repo
6+
get_url:
7+
url=https://raw.githubusercontent.com/GoogleCloudPlatform/kubernetes/master/cluster/addons/cluster-monitoring/influxdb/{{ item }}
8+
dest="{{ kube_config_dir }}/addons/cluster-monitoring/"
9+
force=yes
10+
with_items:
11+
- grafana-service.yaml
12+
- heapster-controller.yaml
13+
- heapster-service.yaml
14+
- influxdb-grafana-controller.yaml
15+
- influxdb-service.yaml

contrib/ansible/roles/kubernetes-addons/tasks/main.yml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@
1313

1414
- include: dns.yml
1515
when: dns_setup
16-
tags: dns
16+
17+
- include: cluster-monitoring.yml
18+
when: cluster_monitoring
19+
20+
- include: cluster-logging.yml
21+
when: cluster_logging
1722

1823
#- name: Get kube-addons script from Kubernetes
1924
# get_url:
@@ -33,15 +38,14 @@
3338
- name: HACK | copy local kube-addon-update.sh
3439
copy: src=kube-addon-update.sh dest={{ kube_script_dir }}/kube-addon-update.sh mode=0755
3540

36-
- name: Copy script to create known_tokens.csv
37-
copy: src=kube-gen-token.sh dest={{ kube_script_dir }}/kube-gen-token.sh mode=0755
38-
39-
- name: Run kube-gen-token script to create {{ kube_config_dir }}/known_tokens.csv
41+
- name: Run kube-gen-token script to create {{ kube_token_dir }}/known_tokens.csv
4042
command: "{{ kube_script_dir }}/kube-gen-token.sh {{ item }}"
4143
environment:
42-
TOKEN_DIR: "{{ kube_config_dir }}"
44+
TOKEN_DIR: "{{ kube_token_dir }}"
4345
with_items:
4446
- "system:dns"
47+
- "system:monitoring"
48+
- "system:logging"
4549
register: gentoken
4650
changed_when: "'Added' in gentoken.stdout"
4751
notify:

contrib/ansible/roles/kubernetes-addons/templates/kube-addons.service.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Description=Kubernetes Addon Object Manager
33
Documentation=https://github.com/GoogleCloudPlatform/kubernetes
44

55
[Service]
6-
Environment="TOKEN_DIR={{ kube_config_dir }}"
6+
Environment="TOKEN_DIR={{ kube_token_dir }}"
77
Environment="KUBECTL_BIN=/usr/bin/kubectl"
88
Environment="KUBERNETES_MASTER_NAME={{ groups['masters'][0] }}"
99
ExecStart={{ kube_script_dir }}/kube-addons.sh

contrib/ansible/roles/kubernetes/defaults/main.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,26 @@ kube_config_dir: /etc/kubernetes
1414
# This is where all the cert scripts and certs will be located
1515
kube_cert_dir: "{{ kube_config_dir }}/certs"
1616

17+
# This is where all of the bearer tokens will be stored
18+
kube_token_dir: "{{ kube_config_dir }}/tokens"
19+
20+
# This is where you can drop yaml/json files and the kubelet will run those
21+
# pods on startup
22+
kube_manifest_dir: "{{ kube_config_dir }}/manifests"
1723

1824
# This is the group that the cert creation scripts chgrp the
1925
# cert files to. Not really changable...
2026
kube_cert_group: kube-cert
27+
28+
# Internal DNS domain name.
29+
# This domain must not be used in your network. Services will be discoverable
30+
# under <service-name>.<namespace>.<domainname>, e.g.
31+
# myservice.default.cluster.local
32+
dns_domain: "{{ cluster_name }}"
33+
34+
# IP address of the DNS server.
35+
# Kubernetes will create a pod with several containers, serving as the DNS
36+
# server and expose it under this IP address. The IP address must be from
37+
# the range specified as kube_service_addresses. This magic will actually
38+
# pick the 10th ip address in the kube_service_addresses range and use that.
39+
dns_server: "{{ kube_service_addresses|ipaddr('net')|ipaddr(10)|ipaddr('address') }}"

contrib/ansible/roles/kubernetes-addons/files/kube-gen-token.sh renamed to contrib/ansible/roles/kubernetes/files/kube-gen-token.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ create_accounts=($@)
2121

2222
touch "${token_file}"
2323
for account in "${create_accounts[@]}"; do
24-
if grep "${account}" "${token_file}" ; then
24+
if grep ",${account}," "${token_file}" ; then
2525
continue
2626
fi
2727
token=$(dd if=/dev/urandom bs=128 count=1 2>/dev/null | base64 | tr -d "=+/" | dd bs=32 count=1 2>/dev/null)
2828
echo "${token},${account},${account}" >> "${token_file}"
29+
echo "${token}" > "${token_dir}/${account}.token"
2930
echo "Added ${account}"
3031
done

contrib/ansible/roles/kubernetes/tasks/certs.yml

Lines changed: 0 additions & 52 deletions
This file was deleted.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
- name: Copy the token gen script
3+
copy:
4+
src=kube-gen-token.sh
5+
dest={{ kube_script_dir }}
6+
mode=u+x
7+
8+
- name: Generate tokens for master components
9+
command: "{{ kube_script_dir }}/kube-gen-token.sh {{ item[0] }}-{{ item[1] }}"
10+
environment:
11+
TOKEN_DIR: "{{ kube_token_dir }}"
12+
with_nested:
13+
- [ "system:controller_manager", "system:scheduler" ]
14+
- "{{ groups['masters'] }}"
15+
register: gentoken
16+
changed_when: "'Added' in gentoken.stdout"
17+
notify:
18+
- restart daemons
19+
20+
- name: Generate tokens for node components
21+
command: "{{ kube_script_dir }}/kube-gen-token.sh {{ item[0] }}-{{ item[1] }}"
22+
environment:
23+
TOKEN_DIR: "{{ kube_token_dir }}"
24+
with_nested:
25+
- [ 'system:kubelet', 'system:proxy' ]
26+
- "{{ groups['nodes'] }}"
27+
register: gentoken
28+
changed_when: "'Added' in gentoken.stdout"
29+
notify:
30+
- restart daemons

contrib/ansible/roles/kubernetes/tasks/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@
1818
notify:
1919
- restart daemons
2020

21-
- include: certs.yml
21+
- include: secrets.yml
2222
tags:
23-
certs
23+
secrets

0 commit comments

Comments
 (0)