Add kubeadm controlplaneEndpoint

Nginx LB(default)
Other LB by kubeadm controlplane
This commit is contained in:
rongzhang 2018-08-18 22:05:35 +08:00
parent 3663061b38
commit 59176ebbb9
5 changed files with 25 additions and 4 deletions

View file

@ -70,7 +70,10 @@
regexp: 'server:' regexp: 'server:'
line: ' server: {{ kube_apiserver_endpoint }}' line: ' server: {{ kube_apiserver_endpoint }}'
backup: yes backup: yes
when: not is_kube_master and kubeadm_discovery_address != kube_apiserver_endpoint when:
- kubeadm_config_api_fqdn is not defined
- not is_kube_master
- kubeadm_discovery_address != kube_apiserver_endpoint
notify: restart kubelet notify: restart kubelet
- name: Update server field in kube-proxy kubeconfig - name: Update server field in kube-proxy kubeconfig
@ -80,10 +83,16 @@
| {{ bin_dir }}/kubectl replace -f - | {{ bin_dir }}/kubectl replace -f -
delegate_to: "{{groups['kube-master']|first}}" delegate_to: "{{groups['kube-master']|first}}"
run_once: true run_once: true
when: is_kube_master and kubeadm_discovery_address != kube_apiserver_endpoint when:
- kubeadm_config_api_fqdn is not defined
- is_kube_master
- kubeadm_discovery_address != kube_apiserver_endpoint
- name: Restart all kube-proxy pods to ensure that they load the new configmap - name: Restart all kube-proxy pods to ensure that they load the new configmap
shell: "{{ bin_dir }}/kubectl delete pod -n kube-system -l k8s-app=kube-proxy" shell: "{{ bin_dir }}/kubectl delete pod -n kube-system -l k8s-app=kube-proxy"
delegate_to: "{{groups['kube-master']|first}}" delegate_to: "{{groups['kube-master']|first}}"
run_once: true run_once: true
when: is_kube_master and kubeadm_discovery_address != kube_apiserver_endpoint when:
- kubeadm_config_api_fqdn is not defined
- is_kube_master
- kubeadm_discovery_address != kube_apiserver_endpoint

View file

@ -91,6 +91,12 @@
kubeadmConfig_api_version: v1alpha2 kubeadmConfig_api_version: v1alpha2
when: kubeadm_output.stdout|version_compare('v1.11.0', '>=') when: kubeadm_output.stdout|version_compare('v1.11.0', '>=')
# Nginx LB(default), If kubeadm_config_api_fqdn is defined, use other LB by kubeadm controlPlaneEndpoint.
- name: set kubeadm_config_api_fqdn define
set_fact:
kubeadm_config_api_fqdn: "{{ apiserver_loadbalancer_domain_name|default('lb-apiserver.kubernetes.local') }}"
when: loadbalancer_apiserver is defined
- name: kubeadm | Create kubeadm config - name: kubeadm | Create kubeadm config
template: template:
src: "kubeadm-config.{{ kubeadmConfig_api_version }}.yaml.j2" src: "kubeadm-config.{{ kubeadmConfig_api_version }}.yaml.j2"

View file

@ -3,6 +3,9 @@ kind: MasterConfiguration
api: api:
advertiseAddress: {{ ip | default(ansible_default_ipv4.address) }} advertiseAddress: {{ ip | default(ansible_default_ipv4.address) }}
bindPort: {{ kube_apiserver_port }} bindPort: {{ kube_apiserver_port }}
{% if groups['kube-master'] | length > 1 and kubeadm_config_api_fqdn is defined %}
controlPlaneEndpoint: {{ kubeadm_config_api_fqdn }}
{% endif %}
etcd: etcd:
endpoints: endpoints:
{% for endpoint in etcd_access_addresses.split(',') %} {% for endpoint in etcd_access_addresses.split(',') %}

View file

@ -3,6 +3,9 @@ kind: MasterConfiguration
api: api:
advertiseAddress: {{ ip | default(ansible_default_ipv4.address) }} advertiseAddress: {{ ip | default(ansible_default_ipv4.address) }}
bindPort: {{ kube_apiserver_port }} bindPort: {{ kube_apiserver_port }}
{% if groups['kube-master'] | length > 1 and kubeadm_config_api_fqdn is defined %}
controlPlaneEndpoint: {{ kubeadm_config_api_fqdn }}
{% endif %}
etcd: etcd:
external: external:
endpoints: endpoints: