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
|
2019-06-04 23:46:12 +08:00
|
|
|
- kubectl
|
2018-05-11 11:07:14 +08:00
|
|
|
tags: upgrade_k8s
|
2017-11-11 19:14:21 +08:00
|
|
|
|
|
|
|
- name: 创建 kubernetes 证书签名请求
|
|
|
|
template: src=kubernetes-csr.json.j2 dest={{ ca_dir }}/kubernetes-csr.json
|
2018-11-28 20:39:51 +08:00
|
|
|
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"
|
2018-11-28 20:39:51 +08:00
|
|
|
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
|
|
|
|
|
|
|
|
- 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"
|
|
|
|
|
2019-03-14 23:51:04 +08:00
|
|
|
- block:
|
|
|
|
- name: 生成 basic-auth 随机密码
|
2020-11-06 20:17:38 +08:00
|
|
|
shell: 'PWD=`head -c 16 /dev/urandom | od -An -t x | tr -d " "`; \
|
2019-03-14 23:51:04 +08:00
|
|
|
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 随机密码
|
2019-05-30 21:37:01 +08:00
|
|
|
set_fact: BASIC_AUTH_PASS={{ TMP_PASS.stdout }}
|
2019-03-14 23:51:04 +08:00
|
|
|
when: 'BASIC_AUTH_ENABLE == "yes" and BASIC_AUTH_PASS == "_pwd_"'
|
2019-05-30 21:37:01 +08:00
|
|
|
tags: restart_master
|
2019-03-14 23:51:04 +08:00
|
|
|
|
2017-11-11 19:14:21 +08:00
|
|
|
- name: 创建 basic-auth.csv
|
|
|
|
template: src=basic-auth.csv.j2 dest={{ ca_dir }}/basic-auth.csv
|
2019-03-14 23:51:04 +08:00
|
|
|
when: 'BASIC_AUTH_ENABLE == "yes"'
|
2019-04-04 09:08:27 +08:00
|
|
|
tags: restart_master
|
2017-11-11 19:14:21 +08:00
|
|
|
|
2020-01-31 12:37:44 +08:00
|
|
|
- name: 替换 kubeconfig 的 apiserver 地址
|
|
|
|
lineinfile:
|
|
|
|
dest: "{{ item }}"
|
|
|
|
regexp: "^ server"
|
|
|
|
line: " server: https://{{ inventory_hostname }}:6443"
|
|
|
|
with_items:
|
|
|
|
- "/root/.kube/config"
|
|
|
|
- "/etc/kubernetes/kube-controller-manager.kubeconfig"
|
|
|
|
- "/etc/kubernetes/kube-scheduler.kubeconfig"
|
|
|
|
tags: upgrade_k8s, restart_master
|
|
|
|
|
2019-05-28 09:10:44 +08:00
|
|
|
- name: 创建 master 服务的 systemd unit 文件
|
|
|
|
template: src={{ item }}.j2 dest=/etc/systemd/system/{{ item }}
|
|
|
|
with_items:
|
|
|
|
- kube-apiserver.service
|
|
|
|
- kube-controller-manager.service
|
|
|
|
- kube-scheduler.service
|
2019-07-04 14:25:32 +08:00
|
|
|
tags: restart_master, upgrade_k8s
|
2019-05-28 09:10:44 +08:00
|
|
|
|
2018-03-16 18:23:34 +08:00
|
|
|
- name: enable master 服务
|
|
|
|
shell: systemctl enable kube-apiserver kube-controller-manager kube-scheduler
|
2018-04-10 18:33:24 +08:00
|
|
|
ignore_errors: true
|
2017-11-11 19:14:21 +08:00
|
|
|
|
2018-03-16 18:23:34 +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
|
2018-03-14 16:53:21 +08:00
|
|
|
|
|
|
|
- name: 以轮询的方式等待master服务启动完成
|
2018-03-16 18:23:34 +08:00
|
|
|
command: "{{ bin_dir }}/kubectl get node"
|
2018-03-14 16:53:21 +08:00
|
|
|
register: result
|
|
|
|
until: result.rc == 0
|
|
|
|
retries: 5
|
|
|
|
delay: 6
|
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权限
|
2019-04-07 20:38:23 +08:00
|
|
|
template: src=basic-auth-rbac.yaml.j2 dest=/opt/kube/basic-auth-rbac.yaml
|
2019-03-26 15:20:54 +08:00
|
|
|
when: 'BASIC_AUTH_ENABLE == "yes"'
|
2019-04-04 09:08:27 +08:00
|
|
|
tags: restart_master
|
2019-03-26 15:20:54 +08:00
|
|
|
|
|
|
|
- name: 创建{{ BASIC_AUTH_USER }}用户rbac权限
|
2019-04-07 20:38:23 +08:00
|
|
|
shell: "{{ bin_dir }}/kubectl apply -f /opt/kube/basic-auth-rbac.yaml"
|
2019-03-26 15:20:54 +08:00
|
|
|
when: 'BASIC_AUTH_ENABLE == "yes"'
|
|
|
|
run_once: true
|
2019-04-04 09:08:27 +08:00
|
|
|
tags: restart_master
|