-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Refactor remove node to allow removing dead nodes and etcd members #5009
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,54 @@ | ||
| --- | ||
| - name: Lookup node IP in kubernetes | ||
| shell: >- | ||
| {{ bin_dir }}/kubectl get nodes {{ node }} | ||
| -o jsonpath='{range.status.addresses[?(@.type=="InternalIP")]}{.address}{"\n"}{end}' | ||
| register: remove_node_ip | ||
| when: | ||
| - inventory_hostname in groups['etcd'] | ||
| - ip is not defined | ||
| - access_ip is not defined | ||
| delegate_to: "{{ groups['etcd']|first }}" | ||
| failed_when: false | ||
|
|
||
| - name: Set node IP | ||
| set_fact: | ||
| node_ip: "{{ ip | default(access_ip | default(remove_node_ip.stdout)) | trim }}" | ||
|
|
||
| - name: Delete node | ||
| command: "{{ bin_dir }}/kubectl delete node {{ item }}" | ||
| with_items: | ||
| - "{{ node.split(',') | default(groups['kube-node']) }}" | ||
| command: "{{ bin_dir }}/kubectl delete node {{ inventory_hostname }}" | ||
| delegate_to: "{{ groups['kube-master']|first }}" | ||
| run_once: true | ||
| ignore_errors: yes | ||
|
|
||
| - name: Lookup etcd member id | ||
| shell: "{{ bin_dir }}/etcdctl --no-sync --endpoints={{ etcd_access_addresses }} member list | grep {{ node_ip }} | cut -d: -f1" | ||
| register: etcd_member_id | ||
| ignore_errors: true | ||
| changed_when: false | ||
| check_mode: no | ||
| tags: | ||
| - facts | ||
| environment: | ||
| ETCDCTL_CERT_FILE: "{{ etcd_cert_dir }}/admin-{{ groups['etcd']|first }}.pem" | ||
| ETCDCTL_KEY_FILE: "{{ etcd_cert_dir }}/admin-{{ groups['etcd']|first }}-key.pem" | ||
| ETCDCTL_CA_FILE: "{{ etcd_cert_dir }}/ca.pem" | ||
| delegate_to: "{{ groups['etcd']|first }}" | ||
| when: inventory_hostname in groups['etcd'] | ||
|
|
||
| - name: Remove etcd member from cluster | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are 3 nodes etcd cluster, if we remove 2 etcd nodes. The kubernetes cluster will not be available. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It will actually function if you remove node 3, then node 2. It will scale down to 1 and then you could rebuild from that |
||
| shell: "{{ bin_dir }}/etcdctl --no-sync --endpoints={{ etcd_access_addresses }} member remove {{ etcd_member_id.stdout }}" | ||
| register: etcd_member_in_cluster | ||
| ignore_errors: true | ||
| changed_when: false | ||
| check_mode: no | ||
| tags: | ||
| - facts | ||
| environment: | ||
| ETCDCTL_CERT_FILE: "{{ etcd_cert_dir }}/admin-{{ groups['etcd']|first }}.pem" | ||
| ETCDCTL_KEY_FILE: "{{ etcd_cert_dir }}/admin-{{ groups['etcd']|first }}-key.pem" | ||
| ETCDCTL_CA_FILE: "{{ etcd_cert_dir }}/ca.pem" | ||
| delegate_to: "{{ groups['etcd']|first }}" | ||
| when: | ||
| - inventory_hostname in groups['etcd'] | ||
| - not etcd_member_id.stdout | ||
Uh oh!
There was an error while loading. Please reload this page.