|
1 |
| -- block: |
2 |
| - - name: 在deploy 节点创建相关目录 |
3 |
| - file: name={{ item }} state=directory |
4 |
| - with_items: |
5 |
| - - /etc/calico/ssl |
6 |
| - - /opt/kube/kube-system/calico |
7 |
| - |
8 |
| - - name: 创建calico 证书请求 |
9 |
| - template: src=calico-csr.json.j2 dest=/etc/calico/ssl/calico-csr.json |
10 |
| - |
11 |
| - - name: 创建 calico证书和私钥 |
12 |
| - shell: "cd /etc/calico/ssl && {{ bin_dir }}/cfssl gencert \ |
13 |
| - -ca={{ ca_dir }}/ca.pem \ |
14 |
| - -ca-key={{ ca_dir }}/ca-key.pem \ |
15 |
| - -config={{ ca_dir }}/ca-config.json \ |
16 |
| - -profile=kubernetes calico-csr.json | {{ bin_dir }}/cfssljson -bare calico" |
17 |
| - |
18 |
| - - name: get calico-etcd-secrets info |
19 |
| - shell: "{{ bin_dir }}/kubectl get secrets -n kube-system" |
20 |
| - register: secrets_info |
21 |
| - |
22 |
| - - name: 创建 calico-etcd-secrets |
23 |
| - shell: "cd /etc/calico/ssl && \ |
24 |
| - {{ bin_dir }}/kubectl create secret generic -n kube-system calico-etcd-secrets \ |
25 |
| - --from-file=etcd-ca={{ ca_dir }}/ca.pem \ |
26 |
| - --from-file=etcd-key=calico-key.pem \ |
27 |
| - --from-file=etcd-cert=calico.pem" |
28 |
| - when: '"calico-etcd-secrets" not in secrets_info.stdout' |
29 |
| - |
30 |
| - - name: 配置 calico DaemonSet yaml文件 |
31 |
| - template: src=calico-{{ calico_ver_main }}.yaml.j2 dest=/opt/kube/kube-system/calico/calico.yaml |
32 |
| - |
33 |
| - delegate_to: "{{ groups.deploy[0] }}" |
34 |
| - run_once: true |
35 |
| - |
36 |
| -- name: node 节点创建calico 相关目录 |
| 1 | +- name: 在节点创建相关目录 |
37 | 2 | file: name={{ item }} state=directory
|
38 | 3 | with_items:
|
39 | 4 | - /etc/calico/ssl
|
40 | 5 | - /etc/cni/net.d
|
41 | 6 | - /opt/kube/images
|
| 7 | + - /opt/kube/kube-system |
42 | 8 |
|
| 9 | +- name: 创建calico 证书请求 |
| 10 | + template: src=calico-csr.json.j2 dest=/etc/calico/ssl/calico-csr.json |
| 11 | + |
| 12 | +- name: 创建 calico证书和私钥 |
| 13 | + shell: "cd /etc/calico/ssl && {{ bin_dir }}/cfssl gencert \ |
| 14 | + -ca={{ ca_dir }}/ca.pem \ |
| 15 | + -ca-key={{ ca_dir }}/ca-key.pem \ |
| 16 | + -config={{ ca_dir }}/ca-config.json \ |
| 17 | + -profile=kubernetes calico-csr.json | {{ bin_dir }}/cfssljson -bare calico" |
| 18 | + |
| 19 | +- name: get calico-etcd-secrets info |
| 20 | + shell: "{{ bin_dir }}/kubectl get secrets -n kube-system" |
| 21 | + register: secrets_info |
| 22 | + run_once: true |
| 23 | + |
| 24 | +- name: 创建 calico-etcd-secrets |
| 25 | + shell: "cd /etc/calico/ssl && \ |
| 26 | + {{ bin_dir }}/kubectl create secret generic -n kube-system calico-etcd-secrets \ |
| 27 | + --from-file=etcd-ca={{ ca_dir }}/ca.pem \ |
| 28 | + --from-file=etcd-key=calico-key.pem \ |
| 29 | + --from-file=etcd-cert=calico.pem" |
| 30 | + when: '"calico-etcd-secrets" not in secrets_info.stdout' |
| 31 | + run_once: true |
| 32 | + |
| 33 | +- name: 配置 calico DaemonSet yaml文件 |
| 34 | + template: src=calico-{{ calico_ver_main }}.yaml.j2 dest=/opt/kube/kube-system/calico.yaml |
| 35 | + |
43 | 36 | # 【可选】推送离线docker 镜像,可以忽略执行错误
|
44 | 37 | - block:
|
45 | 38 | - name: 检查是否已下载离线calico镜像
|
|
79 | 72 |
|
80 | 73 | # 只需单节点执行一次
|
81 | 74 | - name: 运行 calico网络
|
82 |
| - shell: "{{ bin_dir }}/kubectl apply -f /opt/kube/kube-system/calico/ && sleep 5" |
83 |
| - delegate_to: "{{ groups.deploy[0] }}" |
| 75 | + shell: "{{ bin_dir }}/kubectl apply -f /opt/kube/kube-system/calico.yaml" |
84 | 76 | run_once: true
|
85 | 77 |
|
86 | 78 | # 删除原有cni配置
|
|
96 | 88 | #- loopback
|
97 | 89 | - calicoctl
|
98 | 90 |
|
99 |
| -- name: 分发 calico 证书 |
100 |
| - synchronize: src=/etc/calico/ssl/{{ item }} dest=/etc/calico/ssl/{{ item }} |
101 |
| - with_items: |
102 |
| - - calico.pem |
103 |
| - - calico-key.pem |
104 |
| - delegate_to: "{{ groups.deploy[0] }}" |
105 |
| - |
106 | 91 | - name: 准备 calicoctl配置文件
|
107 | 92 | template: src=calicoctl.cfg.j2 dest=/etc/calico/calicoctl.cfg
|
108 | 93 |
|
|
111 | 96 | shell: "{{ bin_dir }}/kubectl get pod -n kube-system -o wide|grep 'calico-node'|grep ' {{ inventory_hostname }} '|awk '{print $3}'"
|
112 | 97 | register: pod_status
|
113 | 98 | until: pod_status.stdout == "Running"
|
114 |
| - delegate_to: "{{ groups.deploy[0] }}" |
115 | 99 | retries: 15
|
116 | 100 | delay: 15
|
117 | 101 | ignore_errors: true
|
0 commit comments