mirror of
https://github.com/kubernetes-sigs/kubespray.git
synced 2026-05-07 09:27:38 -02:30
[calico] add calico apiserver (#8690)
* [calico] add calico apiserver * fix yamllint * remove addext argument * Configure API server with the CA bundle * add check kdd
This commit is contained in:
60
roles/network_plugin/calico/tasks/calico_apiserver_certs.yml
Normal file
60
roles/network_plugin/calico/tasks/calico_apiserver_certs.yml
Normal file
@@ -0,0 +1,60 @@
|
||||
---
|
||||
- name: Calico | Check if calico apiserver exists
|
||||
command: "{{ kubectl }} -n calico-apiserver get secret calico-apiserver-certs"
|
||||
register: calico_apiserver_secret
|
||||
changed_when: false
|
||||
failed_when: false
|
||||
|
||||
- name: Calico | Create ns manifests
|
||||
template:
|
||||
src: "calico-apiserver-ns.yml.j2"
|
||||
dest: "{{ kube_config_dir }}/calico-apiserver-ns.yml"
|
||||
mode: 0644
|
||||
|
||||
- name: Calico | Apply ns manifests
|
||||
kube:
|
||||
kubectl: "{{ bin_dir }}/kubectl"
|
||||
filename: "{{ kube_config_dir }}/calico-apiserver-ns.yml"
|
||||
state: "latest"
|
||||
|
||||
- name: Calico | Ensure calico certs dir
|
||||
file:
|
||||
path: /etc/calico/certs
|
||||
state: directory
|
||||
mode: 0755
|
||||
when: calico_apiserver_secret.rc != 0
|
||||
|
||||
- name: Calico | Copy ssl script for apiserver certs
|
||||
template:
|
||||
src: make-ssl-calico.sh.j2
|
||||
dest: "{{ bin_dir }}/make-ssl-apiserver.sh"
|
||||
mode: 0755
|
||||
when: calico_apiserver_secret.rc != 0
|
||||
|
||||
- name: Calico | Copy ssl config for apiserver certs
|
||||
copy:
|
||||
src: openssl.conf
|
||||
dest: /etc/calico/certs/openssl.conf
|
||||
mode: 0644
|
||||
when: calico_apiserver_secret.rc != 0
|
||||
|
||||
- name: Calico | Generate apiserver certs
|
||||
command: >-
|
||||
{{ bin_dir }}/make-ssl-apiserver.sh
|
||||
-f /etc/calico/certs/openssl.conf
|
||||
-c {{ kube_cert_dir }}
|
||||
-d /etc/calico/certs
|
||||
-s apiserver
|
||||
when: calico_apiserver_secret.rc != 0
|
||||
|
||||
- name: Calico | Create calico apiserver generic secrets
|
||||
command: >-
|
||||
{{ kubectl }} -n calico-apiserver
|
||||
create secret generic {{ item.name }}
|
||||
--from-file={{ item.cert }}
|
||||
--from-file={{ item.key }}
|
||||
with_items:
|
||||
- name: calico-apiserver-certs
|
||||
cert: /etc/calico/certs/apiserver.crt
|
||||
key: /etc/calico/certs/apiserver.key
|
||||
when: calico_apiserver_secret.rc != 0
|
||||
@@ -59,3 +59,15 @@
|
||||
msg: "Your inventory doesn't match the current cluster configuration"
|
||||
when:
|
||||
- calico_pool_conf is defined
|
||||
|
||||
- name: "Check kdd calico_datastore if calico_apiserver_enabled"
|
||||
assert:
|
||||
that: calico_datastore == "kdd"
|
||||
when:
|
||||
- calico_apiserver_enabled
|
||||
|
||||
- name: "Check kdd calico_datastore if typha_enabled"
|
||||
assert:
|
||||
that: calico_datastore == "kdd"
|
||||
when:
|
||||
- typha_enabled
|
||||
|
||||
@@ -53,6 +53,12 @@
|
||||
- typha_secure
|
||||
- inventory_hostname == groups['kube_control_plane'][0]
|
||||
|
||||
- name: Calico | Generate apiserver certs
|
||||
include_tasks: calico_apiserver_certs.yml
|
||||
when:
|
||||
- calico_apiserver_enabled
|
||||
- inventory_hostname == groups['kube_control_plane'][0]
|
||||
|
||||
- name: Calico | Install calicoctl wrapper script
|
||||
template:
|
||||
src: "calicoctl.{{ calico_datastore }}.sh.j2"
|
||||
@@ -362,7 +368,34 @@
|
||||
register: calico_node_typha_manifest
|
||||
when:
|
||||
- inventory_hostname in groups['kube_control_plane']
|
||||
- typha_enabled and calico_datastore == "kdd"
|
||||
- typha_enabled
|
||||
|
||||
- name: Calico | get calico apiserver caBundle
|
||||
command: "{{ bin_dir }}/kubectl get secret -n calico-apiserver calico-apiserver-certs -o jsonpath='{.data.apiserver\\.crt}'"
|
||||
changed_when: false
|
||||
register: calico_apiserver_cabundle
|
||||
when:
|
||||
- inventory_hostname == groups['kube_control_plane'][0]
|
||||
- calico_apiserver_enabled
|
||||
|
||||
- name: Calico | set calico apiserver caBundle fact
|
||||
set_fact:
|
||||
calico_apiserver_cabundle: "{{ calico_apiserver_cabundle.stdout }}"
|
||||
when:
|
||||
- inventory_hostname == groups['kube_control_plane'][0]
|
||||
- calico_apiserver_enabled
|
||||
|
||||
- name: Calico | Create calico manifests for apiserver
|
||||
template:
|
||||
src: "{{ item.file }}.j2"
|
||||
dest: "{{ kube_config_dir }}/{{ item.file }}"
|
||||
mode: 0644
|
||||
with_items:
|
||||
- {name: calico, file: calico-apiserver.yml, type: calico-apiserver}
|
||||
register: calico_apiserver_manifest
|
||||
when:
|
||||
- inventory_hostname in groups['kube_control_plane']
|
||||
- calico_apiserver_enabled
|
||||
|
||||
- name: Start Calico resources
|
||||
kube:
|
||||
@@ -381,6 +414,22 @@
|
||||
loop_control:
|
||||
label: "{{ item.item.file }}"
|
||||
|
||||
- name: Start Calico apiserver resources
|
||||
kube:
|
||||
name: "{{ item.item.name }}"
|
||||
namespace: "calico-apiserver"
|
||||
kubectl: "{{ bin_dir }}/kubectl"
|
||||
resource: "{{ item.item.type }}"
|
||||
filename: "{{ kube_config_dir }}/{{ item.item.file }}"
|
||||
state: "latest"
|
||||
with_items:
|
||||
- "{{ calico_apiserver_manifest.results }}"
|
||||
when:
|
||||
- inventory_hostname == groups['kube_control_plane'][0]
|
||||
- not item is skipped
|
||||
loop_control:
|
||||
label: "{{ item.item.file }}"
|
||||
|
||||
- name: Wait for calico kubeconfig to be created
|
||||
wait_for:
|
||||
path: /etc/cni/net.d/calico-kubeconfig
|
||||
|
||||
@@ -13,8 +13,8 @@
|
||||
when: typha_server_secret.rc != 0
|
||||
|
||||
- name: Calico | Copy ssl script for typha certs
|
||||
copy:
|
||||
src: make-ssl-typha.sh
|
||||
template:
|
||||
src: make-ssl-calico.sh.j2
|
||||
dest: "{{ bin_dir }}/make-ssl-typha.sh"
|
||||
mode: 0755
|
||||
when: typha_server_secret.rc != 0
|
||||
@@ -32,6 +32,7 @@
|
||||
-f /etc/calico/certs/openssl.conf
|
||||
-c {{ kube_cert_dir }}
|
||||
-d /etc/calico/certs
|
||||
-s typha
|
||||
when: typha_server_secret.rc != 0
|
||||
|
||||
- name: Calico | Create typha tls secrets
|
||||
|
||||
Reference in New Issue
Block a user