kubeasz/roles/kube-master/tasks/main.yml

116 lines
4.1 KiB
YAML
Raw Normal View History

2017-11-11 19:14:21 +08:00
- name: 下载 kube-master 二进制
copy: src={{ base_dir }}/bin/{{ item }} dest={{ bin_dir }}/{{ item }} mode=0755
with_items:
- kube-apiserver
- kube-controller-manager
- kube-scheduler
2018-05-11 11:07:14 +08:00
tags: upgrade_k8s
2017-11-11 19:14:21 +08:00
- name: 分发证书相关
synchronize: src={{ ca_dir }}/{{ item }} dest={{ ca_dir }}/{{ item }}
with_items:
- admin.pem
- admin-key.pem
- ca.pem
- ca-key.pem
- ca.csr
- ca-config.json
delegate_to: "{{ groups.deploy[0] }}"
2017-11-11 19:14:21 +08:00
- name: 创建 kubernetes 证书签名请求
template: src=kubernetes-csr.json.j2 dest={{ ca_dir }}/kubernetes-csr.json
tags: change_cert
2017-11-11 19:14:21 +08:00
- name: 创建 kubernetes 证书和私钥
shell: "cd {{ ca_dir }} && {{ bin_dir }}/cfssl gencert \
-ca={{ ca_dir }}/ca.pem \
-ca-key={{ ca_dir }}/ca-key.pem \
-config={{ ca_dir }}/ca-config.json \
-profile=kubernetes kubernetes-csr.json | {{ bin_dir }}/cfssljson -bare kubernetes"
tags: change_cert
2017-11-11 19:14:21 +08:00
2018-06-17 13:07:57 +08:00
# 创建aggregator proxy相关证书
- name: 创建 aggregator proxy证书签名请求
template: src=aggregator-proxy-csr.json.j2 dest={{ ca_dir }}/aggregator-proxy-csr.json
tags: upgrade_k8s
2018-06-17 13:07:57 +08:00
- name: 创建 aggregator-proxy证书和私钥
shell: "cd {{ ca_dir }} && {{ bin_dir }}/cfssl gencert \
-ca={{ ca_dir }}/ca.pem \
-ca-key={{ ca_dir }}/ca-key.pem \
-config={{ ca_dir }}/ca-config.json \
-profile=kubernetes aggregator-proxy-csr.json | {{ bin_dir }}/cfssljson -bare aggregator-proxy"
tags: upgrade_k8s
2018-06-17 13:07:57 +08:00
- block:
- name: 生成 basic-auth 随机密码
shell: 'PWD=`date +%s%N|md5sum|head -c16`; \
sed -i "s/_pwd_/$PWD/g" {{ base_dir }}/roles/kube-master/defaults/main.yml; \
echo $PWD;'
connection: local
register: TMP_PASS
run_once: true
- name: 设置 basic-auth 随机密码
set_fact: BASIC_AUTH_PASS="{{ TMP_PASS.stdout }}"
when: 'BASIC_AUTH_ENABLE == "yes" and BASIC_AUTH_PASS == "_pwd_"'
2017-11-11 19:14:21 +08:00
- name: 创建 basic-auth.csv
template: src=basic-auth.csv.j2 dest={{ ca_dir }}/basic-auth.csv
when: 'BASIC_AUTH_ENABLE == "yes"'
2017-11-11 19:14:21 +08:00
# 为兼容v1.8版本,配置不同 kube-apiserver的systemd unit文件
- name: 获取 k8s 版本信息
shell: "{{ bin_dir }}/kube-apiserver --version"
register: k8s_ver
tags: upgrade_k8s, restart_master
2017-11-11 19:14:21 +08:00
- name: 创建kube-apiserver的systemd unit文件
template: src=kube-apiserver.service.j2 dest=/etc/systemd/system/kube-apiserver.service
2018-05-20 00:17:59 +08:00
tags: upgrade_k8s, restart_master
when: "'v1.8' not in k8s_ver.stdout"
2017-11-11 19:14:21 +08:00
- name: 创建kube-apiserver v1.8的systemd unit文件
template: src=kube-apiserver-v1.8.service.j2 dest=/etc/systemd/system/kube-apiserver.service
tags: upgrade_k8s, restart_master
when: "'v1.8' in k8s_ver.stdout"
2017-11-11 19:14:21 +08:00
- name: 创建kube-controller-manager的systemd unit文件
template: src=kube-controller-manager.service.j2 dest=/etc/systemd/system/kube-controller-manager.service
2018-05-20 00:17:59 +08:00
tags: upgrade_k8s, restart_master
2017-11-11 19:14:21 +08:00
- name: 创建kube-scheduler的systemd unit文件
template: src=kube-scheduler.service.j2 dest=/etc/systemd/system/kube-scheduler.service
2018-05-20 00:17:59 +08:00
tags: upgrade_k8s, restart_master
2017-11-11 19:14:21 +08:00
- name: enable master 服务
shell: systemctl enable kube-apiserver kube-controller-manager kube-scheduler
ignore_errors: true
2017-11-11 19:14:21 +08:00
- name: 启动 master 服务
shell: "systemctl daemon-reload && systemctl restart kube-apiserver && \
systemctl restart kube-controller-manager && systemctl restart kube-scheduler"
2018-05-20 00:17:59 +08:00
tags: upgrade_k8s, restart_master
- name: 以轮询的方式等待master服务启动完成
command: "{{ bin_dir }}/kubectl get node"
register: result
until: result.rc == 0
retries: 5
delay: 6
delegate_to: "{{ groups.deploy[0] }}"
run_once: True
2018-05-20 00:17:59 +08:00
tags: upgrade_k8s, restart_master
2019-03-26 15:20:54 +08:00
- name: 配置{{ BASIC_AUTH_USER }}用户rbac权限
template: src=admin-user-binding.yaml.j2 dest=/opt/kube/admin-user-binding.yaml
when: 'BASIC_AUTH_ENABLE == "yes"'
delegate_to: "{{ groups.deploy[0] }}"
run_once: true
- name: 创建{{ BASIC_AUTH_USER }}用户rbac权限
shell: "{{ bin_dir }}/kubectl apply -f /opt/kube/admin-user-binding.yaml"
when: 'BASIC_AUTH_ENABLE == "yes"'
delegate_to: "{{ groups.deploy[0] }}"
run_once: true