Add rbac for calico policy controller
This commit is contained in:
parent
c1fd468687
commit
a035583f86
9 changed files with 73 additions and 15 deletions
|
@ -9,3 +9,4 @@
|
||||||
state: "{{item.changed | ternary('latest','present') }}"
|
state: "{{item.changed | ternary('latest','present') }}"
|
||||||
with_items: "{{ canal_manifests.results }}"
|
with_items: "{{ canal_manifests.results }}"
|
||||||
failed_when: canal_manifests|failed and "Error from server (AlreadyExists)" not in canal_manifests.msg
|
failed_when: canal_manifests|failed and "Error from server (AlreadyExists)" not in canal_manifests.msg
|
||||||
|
when: inventory_hostname == groups['kube-master'][0]
|
||||||
|
|
|
@ -8,3 +8,8 @@ calico_policy_controller_memory_requests: 64M
|
||||||
# SSL
|
# SSL
|
||||||
calico_cert_dir: "/etc/calico/certs"
|
calico_cert_dir: "/etc/calico/certs"
|
||||||
canal_cert_dir: "/etc/canal/certs"
|
canal_cert_dir: "/etc/canal/certs"
|
||||||
|
|
||||||
|
rbac_resources:
|
||||||
|
- sa
|
||||||
|
- clusterrole
|
||||||
|
- clusterrolebinding
|
||||||
|
|
|
@ -4,19 +4,27 @@
|
||||||
when: kube_network_plugin == 'canal'
|
when: kube_network_plugin == 'canal'
|
||||||
tags: [facts, canal]
|
tags: [facts, canal]
|
||||||
|
|
||||||
- name: Write calico-policy-controller yaml
|
- name: Create calico-policy-controller manifests
|
||||||
template:
|
template:
|
||||||
src: calico-policy-controller.yml.j2
|
src: "{{item.file}}.j2"
|
||||||
dest: "{{kube_config_dir}}/calico-policy-controller.yml"
|
dest: "{{kube_config_dir}}/{{item.file}}"
|
||||||
when: inventory_hostname == groups['kube-master'][0]
|
with_items:
|
||||||
tags: canal
|
- {name: calico-policy-controller, file: calico-policy-controller.yml, type: rs}
|
||||||
|
- {name: calico-policy-controller, file: calico-policy-sa.yml, type: sa}
|
||||||
|
- {name: calico-policy-controller, file: calico-policy-cr.yml, type: clusterrole}
|
||||||
|
- {name: calico-policy-controller, file: calico-policy-crb.yml, type: clusterrolebinding}
|
||||||
|
register: calico_policy_manifests
|
||||||
|
when:
|
||||||
|
- rbac_enabled or item.type not in rbac_resources
|
||||||
|
|
||||||
- name: Start of Calico policy controller
|
- name: Start of Calico policy controller
|
||||||
kube:
|
kube:
|
||||||
name: "calico-policy-controller"
|
name: "{{item.item.name}}"
|
||||||
kubectl: "{{bin_dir}}/kubectl"
|
|
||||||
filename: "{{kube_config_dir}}/calico-policy-controller.yml"
|
|
||||||
namespace: "{{ system_namespace }}"
|
namespace: "{{ system_namespace }}"
|
||||||
resource: "rs"
|
kubectl: "{{bin_dir}}/kubectl"
|
||||||
|
resource: "{{item.item.type}}"
|
||||||
|
filename: "{{kube_config_dir}}/{{item.item.file}}"
|
||||||
|
state: "{{item.changed | ternary('latest','present') }}"
|
||||||
|
with_items: "{{ calico_policy_manifests.results }}"
|
||||||
|
failed_when: calico_policy_manifests|failed and "Error from server (AlreadyExists)" not in calico_policy_manifests.msg
|
||||||
when: inventory_hostname == groups['kube-master'][0]
|
when: inventory_hostname == groups['kube-master'][0]
|
||||||
tags: canal
|
|
||||||
|
|
|
@ -21,6 +21,9 @@ spec:
|
||||||
k8s-app: calico-policy
|
k8s-app: calico-policy
|
||||||
spec:
|
spec:
|
||||||
hostNetwork: true
|
hostNetwork: true
|
||||||
|
{% if rbac_enabled %}
|
||||||
|
serviceAccountName: calico-policy-controller
|
||||||
|
{% endif %}
|
||||||
tolerations:
|
tolerations:
|
||||||
- effect: NoSchedule
|
- effect: NoSchedule
|
||||||
operator: Exists
|
operator: Exists
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
---
|
||||||
|
kind: ClusterRole
|
||||||
|
apiVersion: rbac.authorization.k8s.io/v1beta1
|
||||||
|
metadata:
|
||||||
|
name: calico-policy-controller
|
||||||
|
namespace: {{ system_namespace }}
|
||||||
|
rules:
|
||||||
|
- apiGroups:
|
||||||
|
- ""
|
||||||
|
- extensions
|
||||||
|
resources:
|
||||||
|
- pods
|
||||||
|
- namespaces
|
||||||
|
- networkpolicies
|
||||||
|
verbs:
|
||||||
|
- watch
|
||||||
|
- list
|
|
@ -0,0 +1,13 @@
|
||||||
|
---
|
||||||
|
kind: ClusterRoleBinding
|
||||||
|
apiVersion: rbac.authorization.k8s.io/v1beta1
|
||||||
|
metadata:
|
||||||
|
name: calico-policy-controller
|
||||||
|
roleRef:
|
||||||
|
apiGroup: rbac.authorization.k8s.io
|
||||||
|
kind: ClusterRole
|
||||||
|
name: calico-policy-controller
|
||||||
|
subjects:
|
||||||
|
- kind: ServiceAccount
|
||||||
|
name: calico-policy-controller
|
||||||
|
namespace: {{ system_namespace }}
|
|
@ -0,0 +1,8 @@
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: ServiceAccount
|
||||||
|
metadata:
|
||||||
|
name: calico-policy-controller
|
||||||
|
namespace: {{ system_namespace }}
|
||||||
|
labels:
|
||||||
|
kubernetes.io/cluster-service: "true"
|
|
@ -32,20 +32,21 @@
|
||||||
delegate_to: "{{groups['etcd'][0]}}"
|
delegate_to: "{{groups['etcd'][0]}}"
|
||||||
run_once: true
|
run_once: true
|
||||||
|
|
||||||
- name: Canal | Create canal node rbac configuration
|
- name: Canal | Create canal node manifests
|
||||||
template:
|
template:
|
||||||
src: "{{item.file}}.j2"
|
src: "{{item.file}}.j2"
|
||||||
dest: "{{kube_config_dir}}/{{item.file}}"
|
dest: "{{kube_config_dir}}/{{item.file}}"
|
||||||
with_items:
|
with_items:
|
||||||
- {name: canal-config, file: canal-config.yml, type: cm}
|
- {name: canal-config, file: canal-config.yaml, type: cm}
|
||||||
- {name: canal-node, file: canal-node.yml, type: ds}
|
- {name: canal-node, file: canal-node.yaml, type: ds}
|
||||||
- {name: canal, file: canal-node-sa.yml, type: sa}
|
- {name: canal, file: canal-node-sa.yml, type: sa}
|
||||||
- {name: calico, file: canal-cr-calico.yml, type: clusterrole}
|
- {name: calico, file: canal-cr-calico.yml, type: clusterrole}
|
||||||
- {name: flannel, file: canal-cr-flannel.yml, type: clusterrole}
|
- {name: flannel, file: canal-cr-flannel.yml, type: clusterrole}
|
||||||
- {name: canal-calico, file: canal-cr-calico.yml, type: clusterrolebinding}
|
- {name: canal-calico, file: canal-crb-calico.yml, type: clusterrolebinding}
|
||||||
- {name: canal-flannel, file: canal-cr-flannel.yml, type: clusterrolebinding}
|
- {name: canal-flannel, file: canal-crb-flannel.yml, type: clusterrolebinding}
|
||||||
register: canal_manifests
|
register: canal_manifests
|
||||||
when:
|
when:
|
||||||
|
- inventory_hostname in groups['kube-master']
|
||||||
- rbac_enabled or item.type not in rbac_resources
|
- rbac_enabled or item.type not in rbac_resources
|
||||||
|
|
||||||
- name: Canal | Copy cni plugins from hyperkube
|
- name: Canal | Copy cni plugins from hyperkube
|
||||||
|
|
|
@ -19,7 +19,9 @@ spec:
|
||||||
k8s-app: canal-node
|
k8s-app: canal-node
|
||||||
spec:
|
spec:
|
||||||
hostNetwork: true
|
hostNetwork: true
|
||||||
|
{% if rbac_enabled %}
|
||||||
serviceAccountName: canal
|
serviceAccountName: canal
|
||||||
|
{% endif %}
|
||||||
tolerations:
|
tolerations:
|
||||||
- effect: NoSchedule
|
- effect: NoSchedule
|
||||||
operator: Exists
|
operator: Exists
|
||||||
|
|
Loading…
Reference in a new issue