0c7e1889e4
This allows `kube_apiserver_insecure_port` to be set to 0 (disabled). It's working, but so far I have had to: 1. Make the `uri` module "Wait for apiserver up" checks use `kube_apiserver_port` (HTTPS) 2. Add apiserver client cert/key to the "Wait for apiserver up" checks 3. Update apiserver liveness probe to use HTTPS ports 4. Set `kube_api_anonymous_auth` to true to allow liveness probe to hit apiserver's /healthz over HTTPS (livenessProbes can't use client cert/key unfortunately) 5. RBAC has to be enabled. Anonymous requests are in the `system:unauthenticated` group which is granted access to /healthz by one of RBAC's default ClusterRoleBindings. An equivalent ABAC rule could allow this as well. Changes 1 and 2 should work for everyone, but 3, 4, and 5 require new coupling of currently independent configuration settings. So I also added a new settings check. Options: 1. The problem goes away if you have both anonymous-auth and RBAC enabled. This is how kubeadm does it. This may be the best way to go since RBAC is already on by default but anonymous auth is not. 2. Include conditional templates to set a different liveness probe for possible combinations of `kube_apiserver_insecure_port = 0`, RBAC, and `kube_api_anonymous_auth` (won't be possible to cover every case without a guaranteed authorizer for the secure port) 3. Use basic auth headers for the liveness probe (I really don't like this, it adds a new dependency on basic auth which I'd also like to leave independently configurable, and it requires encoded passwords in the apiserver manifest) Option 1 seems like the clear winner to me, but is there a reason we wouldn't want anonymous-auth on by default? The apiserver binary defaults anonymous-auth to true, but kubespray's default was false.
59 lines
1.8 KiB
YAML
59 lines
1.8 KiB
YAML
---
|
|
- name: Kubernetes Apps | Wait for kube-apiserver
|
|
uri:
|
|
url: "{{ kube_apiserver_endpoint }}/healthz"
|
|
validate_certs: no
|
|
client_cert: "{{ kube_cert_dir }}/apiserver.pem"
|
|
client_key: "{{ kube_cert_dir }}/apiserver-key.pem"
|
|
register: result
|
|
until: result.status == 200
|
|
retries: 10
|
|
delay: 6
|
|
when: inventory_hostname == groups['kube-master'][0]
|
|
|
|
- name: Kubernetes Apps | Add ClusterRoleBinding to admit nodes
|
|
template:
|
|
src: "node-crb.yml.j2"
|
|
dest: "{{ kube_config_dir }}/node-crb.yml"
|
|
register: node_crb_manifest
|
|
when: rbac_enabled
|
|
|
|
- name: Apply workaround to allow all nodes with cert O=system:nodes to register
|
|
kube:
|
|
name: "system:node"
|
|
kubectl: "{{bin_dir}}/kubectl"
|
|
resource: "clusterrolebinding"
|
|
filename: "{{ kube_config_dir }}/node-crb.yml"
|
|
state: latest
|
|
when:
|
|
- rbac_enabled
|
|
- node_crb_manifest.changed
|
|
|
|
# This is not a cluster role, but should be run after kubeconfig is set on master
|
|
- name: Write kube system namespace manifest
|
|
template:
|
|
src: namespace.j2
|
|
dest: "{{kube_config_dir}}/{{system_namespace}}-ns.yml"
|
|
when: inventory_hostname == groups['kube-master'][0]
|
|
tags:
|
|
- apps
|
|
|
|
- name: Check if kube system namespace exists
|
|
command: "{{ bin_dir }}/kubectl get ns {{system_namespace}}"
|
|
register: 'kubesystem'
|
|
changed_when: False
|
|
failed_when: False
|
|
when: inventory_hostname == groups['kube-master'][0]
|
|
tags:
|
|
- apps
|
|
|
|
- name: Create kube system namespace
|
|
command: "{{ bin_dir }}/kubectl create -f {{kube_config_dir}}/{{system_namespace}}-ns.yml"
|
|
retries: 4
|
|
delay: "{{ retry_stagger | random + 3 }}"
|
|
register: create_system_ns
|
|
until: create_system_ns.rc == 0
|
|
changed_when: False
|
|
when: inventory_hostname == groups['kube-master'][0] and kubesystem.rc != 0
|
|
tags:
|
|
- apps
|