Skip to content

Commit

Permalink
Add tags to deploy components by --tags option (kubernetes-sigs#2960)
Browse files Browse the repository at this point in the history
* Add tags for cert serial tasks

This will help facilitate tag-based deployment of specific components.

* fixup kubernetes node
  • Loading branch information
mattymo authored Jul 6, 2018
1 parent 0b939a4 commit 5c617c5
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 15 deletions.
52 changes: 52 additions & 0 deletions docs/upgrades.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,55 @@ kubernetes-apps/rotate_tokens role, only pods in kube-system are destroyed and
recreated. All other invalidated service account tokens are cleaned up
automatically, but other pods are not deleted out of an abundance of caution
for impact to user deployed pods.

### Component-based upgrades

A deployer may want to upgrade specific components in order to minimize risk
or save time. This strategy is not covered by CI as of this writing, so it is
not guaranteed to work.

These commands are useful only for upgrading fully-deployed, healthy, existing
hosts. This will definitely not work for undeployed or partially deployed
hosts.

Upgrade etcd:

```
ansible-playbook -b -i inventory/sample/hosts.ini cluster.yml --tags=etcd
```

Upgrade vault:

```
ansible-playbook -b -i inventory/sample/hosts.ini cluster.yml --tags=vault
```

Upgrade kubelet:

```
ansible-playbook -b -i inventory/sample/hosts.ini cluster.yml --tags=node --skip-tags=k8s-gen-certs,k8s-gen-tokens
```

Upgrade Kubernetes master components:

```
ansible-playbook -b -i inventory/sample/hosts.ini cluster.yml --tags=master
```

Upgrade network plugins:

```
ansible-playbook -b -i inventory/sample/hosts.ini cluster.yml --tags=network
```

Upgrade all add-ons:

```
ansible-playbook -b -i inventory/sample/hosts.ini cluster.yml --tags=apps
```

Upgrade just helm (assuming `helm_enabled` is true):

```
ansible-playbook -b -i inventory/sample/hosts.ini cluster.yml --tags=helm
```
6 changes: 6 additions & 0 deletions roles/etcd/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,17 @@
register: "etcd_client_cert_serial_result"
changed_when: false
when: inventory_hostname in groups['k8s-cluster']|union(groups['etcd'])|union(groups['calico-rr']|default([]))|unique|sort
tags:
- master
- network

- name: Set etcd_client_cert_serial
set_fact:
etcd_client_cert_serial: "{{ etcd_client_cert_serial_result.stdout }}"
when: inventory_hostname in groups['k8s-cluster']|union(groups['etcd'])|union(groups['calico-rr']|default([]))|unique|sort
tags:
- master
- network

- include_tasks: "install_{{ etcd_deployment_type }}.yml"
when: is_etcd_master
Expand Down
15 changes: 0 additions & 15 deletions roles/kubernetes/node/tasks/install.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,4 @@
---
- name: install | Set SSL CA directories
set_fact:
ssl_ca_dirs: "[
{% if ansible_os_family in ['CoreOS', 'Container Linux by CoreOS'] -%}
'/usr/share/ca-certificates',
{% elif ansible_os_family == 'RedHat' -%}
'/etc/pki/tls',
'/etc/pki/ca-trust',
{% elif ansible_os_family == 'Debian' -%}
'/usr/share/ca-certificates',
{% endif -%}
]"
tags:
- facts

- name: Set kubelet deployment to host if kubeadm is enabled
set_fact:
kubelet_deployment_type: host
Expand Down
16 changes: 16 additions & 0 deletions roles/kubernetes/secrets/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
- import_tasks: check-certs.yml
tags:
- k8s-secrets
- k8s-gen-certs
- facts

- import_tasks: check-tokens.yml
tags:
- k8s-secrets
- k8s-gen-tokens
- facts

- name: Make sure the certificate directory exits
Expand Down Expand Up @@ -70,10 +72,12 @@
- include_tasks: "gen_certs_{{ cert_management }}.yml"
tags:
- k8s-secrets
- k8s-gen-certs

- import_tasks: upd_ca_trust.yml
tags:
- k8s-secrets
- k8s-gen-certs

- name: "Gen_certs | Get certificate serials on kube masters"
shell: "openssl x509 -in {{ kube_cert_dir }}/{{ item }} -noout -serial | cut -d= -f2"
Expand All @@ -85,6 +89,10 @@
- "kube-controller-manager.pem"
- "kube-scheduler.pem"
when: inventory_hostname in groups['kube-master']
tags:
- master
- kubelet
- node

- name: "Gen_certs | set kube master certificate serial facts"
set_fact:
Expand All @@ -93,6 +101,10 @@
controller_manager_cert_serial: "{{ master_certificate_serials.results[2].stdout|default() }}"
scheduler_cert_serial: "{{ master_certificate_serials.results[3].stdout|default() }}"
when: inventory_hostname in groups['kube-master']
tags:
- master
- kubelet
- node

- name: "Gen_certs | Get certificate serials on kube nodes"
shell: "openssl x509 -in {{ kube_cert_dir }}/{{ item }} -noout -serial | cut -d= -f2"
Expand All @@ -108,7 +120,11 @@
kubelet_cert_serial: "{{ node_certificate_serials.results[0].stdout|default() }}"
kube_proxy_cert_serial: "{{ node_certificate_serials.results[1].stdout|default() }}"
when: inventory_hostname in groups['k8s-cluster']
tags:
- kubelet
- node

- import_tasks: gen_tokens.yml
tags:
- k8s-secrets
- k8s-gen-tokens
12 changes: 12 additions & 0 deletions roles/kubespray-defaults/defaults/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,18 @@ proxy_env:
https_proxy: "{{ https_proxy| default ('') }}"
no_proxy: "{{ no_proxy| default ('') }}"

ssl_ca_dirs: >-
[
{% if ansible_os_family in ['CoreOS', 'Container Linux by CoreOS'] -%}
'/usr/share/ca-certificates',
{% elif ansible_os_family == 'RedHat' -%}
'/etc/pki/tls',
'/etc/pki/ca-trust',
{% elif ansible_os_family == 'Debian' -%}
'/usr/share/ca-certificates',
{% endif -%}
]
# Vars for pointing to kubernetes api endpoints
is_kube_master: "{{ inventory_hostname in groups['kube-master'] }}"
kube_apiserver_count: "{{ groups['kube-master'] | length }}"
Expand Down

0 comments on commit 5c617c5

Please sign in to comment.