certs for system:kube-controller-manager system:kube-scheduler

This commit is contained in:
jwfang 2017-06-16 14:21:21 +08:00
parent 8b58394d8c
commit 0ee229488e
8 changed files with 143 additions and 45 deletions

View file

@ -60,12 +60,11 @@
when: kubesystem|failed and inventory_hostname == groups['kube-master'][0] when: kubesystem|failed and inventory_hostname == groups['kube-master'][0]
tags: apps tags: apps
- name: Write kube-controller-manager manifest - name: Write kube-scheduler kubeconfig
template: template:
src: manifests/kube-controller-manager.manifest.j2 src: kube-scheduler-kubeconfig.yaml.j2
dest: "{{ kube_manifest_dir }}/kube-controller-manager.manifest" dest: "{{ kube_config_dir }}/kube-scheduler-kubeconfig.yaml"
notify: Master | wait for kube-controller-manager tags: kube-scheduler
tags: kube-controller-manager
- name: Write kube-scheduler manifest - name: Write kube-scheduler manifest
template: template:
@ -74,6 +73,19 @@
notify: Master | wait for kube-scheduler notify: Master | wait for kube-scheduler
tags: kube-scheduler tags: kube-scheduler
- name: Write kube-controller-manager kubeconfig
template:
src: kube-controller-manager-kubeconfig.yaml.j2
dest: "{{ kube_config_dir }}/kube-controller-manager-kubeconfig.yaml"
tags: kube-controller-manager
- name: Write kube-controller-manager manifest
template:
src: manifests/kube-controller-manager.manifest.j2
dest: "{{ kube_manifest_dir }}/kube-controller-manager.manifest"
notify: Master | wait for kube-controller-manager
tags: kube-controller-manager
- include: post-upgrade.yml - include: post-upgrade.yml
tags: k8s-post-upgrade tags: k8s-post-upgrade

View file

@ -0,0 +1,18 @@
apiVersion: v1
kind: Config
clusters:
- name: local
cluster:
certificate-authority: {{ kube_cert_dir }}/ca.pem
server: {{ kube_apiserver_endpoint }}
users:
- name: kube-controller-manager
user:
client-certificate: {{ kube_cert_dir }}/kube-controller-manager.pem
client-key: {{ kube_cert_dir }}/kube-controller-manager-key.pem
contexts:
- context:
cluster: local
user: kube-controller-manager
name: kube-controller-manager-{{ cluster_name }}
current-context: kube-controller-manager-{{ cluster_name }}

View file

@ -0,0 +1,18 @@
apiVersion: v1
kind: Config
clusters:
- name: local
cluster:
certificate-authority: {{ kube_cert_dir }}/ca.pem
server: {{ kube_apiserver_endpoint }}
users:
- name: kube-scheduler
user:
client-certificate: {{ kube_cert_dir }}/kube-scheduler.pem
client-key: {{ kube_cert_dir }}/kube-scheduler-key.pem
contexts:
- context:
cluster: local
user: kube-scheduler
name: kube-scheduler-{{ cluster_name }}
current-context: kube-scheduler-{{ cluster_name }}

View file

@ -24,7 +24,7 @@ spec:
command: command:
- /hyperkube - /hyperkube
- controller-manager - controller-manager
- --master={{ kube_apiserver_endpoint }} - --kubeconfig={{ kube_config_dir }}/kube-controller-manager-kubeconfig.yaml
- --leader-elect=true - --leader-elect=true
- --service-account-private-key-file={{ kube_cert_dir }}/apiserver-key.pem - --service-account-private-key-file={{ kube_cert_dir }}/apiserver-key.pem
- --root-ca-file={{ kube_cert_dir }}/ca.pem - --root-ca-file={{ kube_cert_dir }}/ca.pem
@ -61,20 +61,36 @@ spec:
initialDelaySeconds: 30 initialDelaySeconds: 30
timeoutSeconds: 10 timeoutSeconds: 10
volumeMounts: volumeMounts:
- mountPath: {{ kube_cert_dir }} - mountPath: /etc/ssl/certs
name: ssl-certs-kubernetes name: ssl-certs-host
readOnly: true
- mountPath: "{{kube_config_dir}}/ssl"
name: etc-kube-ssl
readOnly: true
- mountPath: "{{ kube_config_dir }}/kube-controller-manager-kubeconfig.yaml"
name: kubeconfig
readOnly: true readOnly: true
{% if cloud_provider is defined and cloud_provider in ["openstack", "azure", "vsphere" ] %} {% if cloud_provider is defined and cloud_provider in ["openstack", "azure", "vsphere" ] %}
- mountPath: {{ kube_config_dir }}/cloud_config - mountPath: "{{ kube_config_dir }}/cloud_config"
name: cloudconfig name: cloudconfig
readOnly: true readOnly: true
{% endif %} {% endif %}
volumes: volumes:
- hostPath: - name: ssl-certs-host
path: {{ kube_cert_dir }} hostPath:
name: ssl-certs-kubernetes {% if ansible_os_family == 'RedHat' %}
path: /etc/pki/tls
{% else %}
path: /usr/share/ca-certificates
{% endif %}
- name: etc-kube-ssl
hostPath:
path: "{{ kube_config_dir }}/ssl"
- name: kubeconfig
hostPath:
path: "{{ kube_config_dir }}/kube-controller-manager-kubeconfig.yaml"
{% if cloud_provider is defined and cloud_provider in ["openstack", "azure", "vsphere"] %} {% if cloud_provider is defined and cloud_provider in ["openstack", "azure", "vsphere"] %}
- hostPath: - hostPath:
path: {{ kube_config_dir }}/cloud_config path: "{{ kube_config_dir }}/cloud_config"
name: cloudconfig name: cloudconfig
{% endif %} {% endif %}

View file

@ -25,7 +25,7 @@ spec:
- /hyperkube - /hyperkube
- scheduler - scheduler
- --leader-elect=true - --leader-elect=true
- --master={{ kube_apiserver_endpoint }} - --kubeconfig={{ kube_config_dir }}/kube-scheduler-kubeconfig.yaml
- --v={{ kube_log_level }} - --v={{ kube_log_level }}
{% if scheduler_custom_flags is string %} {% if scheduler_custom_flags is string %}
- {{ scheduler_custom_flags }} - {{ scheduler_custom_flags }}
@ -41,3 +41,27 @@ spec:
port: 10251 port: 10251
initialDelaySeconds: 30 initialDelaySeconds: 30
timeoutSeconds: 10 timeoutSeconds: 10
volumeMounts:
- mountPath: /etc/ssl/certs
name: ssl-certs-host
readOnly: true
- mountPath: "{{ kube_config_dir }}/ssl"
name: etc-kube-ssl
readOnly: true
- mountPath: "{{ kube_config_dir }}/kube-scheduler-kubeconfig.yaml"
name: kubeconfig
readOnly: true
volumes:
- name: ssl-certs-host
hostPath:
{% if ansible_os_family == 'RedHat' %}
path: /etc/pki/tls
{% else %}
path: /usr/share/ca-certificates
{% endif %}
- name: etc-kube-ssl
hostPath:
path: "{{ kube_config_dir }}/ssl"
- name: kubeconfig
hostPath:
path: "{{ kube_config_dir }}/kube-scheduler-kubeconfig.yaml"

View file

@ -41,14 +41,14 @@ spec:
- mountPath: /etc/ssl/certs - mountPath: /etc/ssl/certs
name: ssl-certs-host name: ssl-certs-host
readOnly: true readOnly: true
- mountPath: {{kube_config_dir}}/kube-proxy-kubeconfig.yaml - mountPath: "{{ kube_config_dir }}/ssl"
name: "kubeconfig" name: etc-kube-ssl
readOnly: true readOnly: true
- mountPath: {{kube_config_dir}}/ssl - mountPath: "{{ kube_config_dir }}/kube-proxy-kubeconfig.yaml"
name: "etc-kube-ssl" name: kubeconfig
readOnly: true readOnly: true
- mountPath: /var/run/dbus - mountPath: /var/run/dbus
name: "var-run-dbus" name: var-run-dbus
readOnly: false readOnly: false
volumes: volumes:
- name: ssl-certs-host - name: ssl-certs-host
@ -58,12 +58,12 @@ spec:
{% else %} {% else %}
path: /usr/share/ca-certificates path: /usr/share/ca-certificates
{% endif %} {% endif %}
- name: "kubeconfig" - name: etc-kube-ssl
hostPath:
path: "{{kube_config_dir}}/kube-proxy-kubeconfig.yaml"
- name: "etc-kube-ssl"
hostPath: hostPath:
path: "{{ kube_config_dir }}/ssl" path: "{{ kube_config_dir }}/ssl"
- name: "var-run-dbus" - name: kubeconfig
hostPath: hostPath:
path: "/var/run/dbus" path: "{{ kube_config_dir }}/kube-proxy-kubeconfig.yaml"
- name: var-run-dbus
hostPath:
path: /var/run/dbus

View file

@ -72,22 +72,30 @@ else
openssl req -x509 -new -nodes -key ca-key.pem -days 10000 -out ca.pem -subj "/CN=kube-ca" > /dev/null 2>&1 openssl req -x509 -new -nodes -key ca-key.pem -days 10000 -out ca.pem -subj "/CN=kube-ca" > /dev/null 2>&1
fi fi
gen_key_and_cert() {
local name=$1
local subject=$2
openssl genrsa -out ${name}-key.pem 2048 > /dev/null 2>&1
openssl req -new -key ${name}-key.pem -out ${name}.csr -subj "${subject}" -config ${CONFIG} > /dev/null 2>&1
openssl x509 -req -in ${name}.csr -CA ca.pem -CAkey ca-key.pem -CAcreateserial -out ${name}.pem -days 3650 -extensions v3_req -extfile ${CONFIG} > /dev/null 2>&1
}
if [ ! -e "$SSLDIR/ca-key.pem" ]; then if [ ! -e "$SSLDIR/ca-key.pem" ]; then
# kube-apiserver key # kube-apiserver
openssl genrsa -out apiserver-key.pem 2048 > /dev/null 2>&1 gen_key_and_cert "apiserver" "/CN=kube-apiserver"
openssl req -new -key apiserver-key.pem -out apiserver.csr -subj "/CN=kube-apiserver" -config ${CONFIG} > /dev/null 2>&1
openssl x509 -req -in apiserver.csr -CA ca.pem -CAkey ca-key.pem -CAcreateserial -out apiserver.pem -days 3650 -extensions v3_req -extfile ${CONFIG} > /dev/null 2>&1
cat ca.pem >> apiserver.pem cat ca.pem >> apiserver.pem
# kube-scheduler
gen_key_and_cert "kube-scheduler" "/CN=system:kube-scheduler"
# kube-controller-manager
gen_key_and_cert "kube-controller-manager" "/CN=system:kube-controller-manager"
fi fi
# Admins # Admins
if [ -n "$MASTERS" ]; then if [ -n "$MASTERS" ]; then
for host in $MASTERS; do for host in $MASTERS; do
cn="${host%%.*}" cn="${host%%.*}"
# admin key # admin
openssl genrsa -out admin-${host}-key.pem 2048 > /dev/null 2>&1 gen_key_and_cert "admin-${host}" "/CN=kube-admin-${cn}/O=system:masters"
openssl req -new -key admin-${host}-key.pem -out admin-${host}.csr -subj "/CN=kube-admin-${cn}/O=system:masters" > /dev/null 2>&1
openssl x509 -req -in admin-${host}.csr -CA ca.pem -CAkey ca-key.pem -CAcreateserial -out admin-${host}.pem -days 3650 > /dev/null 2>&1
done done
fi fi
@ -95,10 +103,7 @@ fi
if [ -n "$HOSTS" ]; then if [ -n "$HOSTS" ]; then
for host in $HOSTS; do for host in $HOSTS; do
cn="${host%%.*}" cn="${host%%.*}"
# node key gen_key_and_cert "node-${host}" "/CN=kube-node-${cn}/O=system:nodes"
openssl genrsa -out node-${host}-key.pem 2048 > /dev/null 2>&1
openssl req -new -key node-${host}-key.pem -out node-${host}.csr -subj "/CN=kube-node-${cn}/O=system:nodes" > /dev/null 2>&1
openssl x509 -req -in node-${host}.csr -CA ca.pem -CAkey ca-key.pem -CAcreateserial -out node-${host}.pem -days 3650 > /dev/null 2>&1
done done
fi fi
@ -106,13 +111,10 @@ fi
if [ -n "$HOSTS" ]; then if [ -n "$HOSTS" ]; then
for host in $HOSTS; do for host in $HOSTS; do
cn="${host%%.*}" cn="${host%%.*}"
# kube-proxy key # kube-proxy
openssl genrsa -out kube-proxy-${host}-key.pem 2048 > /dev/null 2>&1 gen_key_and_cert "kube-proxy-${host}" "/CN=system:kube-proxy"
openssl req -new -key kube-proxy-${host}-key.pem -out kube-proxy-${host}.csr -subj "/CN=system:kube-proxy" > /dev/null 2>&1
openssl x509 -req -in kube-proxy-${host}.csr -CA ca.pem -CAkey ca-key.pem -CAcreateserial -out kube-proxy-${host}.pem -days 3650 > /dev/null 2>&1
done done
fi fi
# Install certs # Install certs
mv *.pem ${SSLDIR}/ mv *.pem ${SSLDIR}/

View file

@ -56,17 +56,25 @@
- set_fact: - set_fact:
all_master_certs: "['ca-key.pem', all_master_certs: "['ca-key.pem',
'apiserver.pem',
'apiserver-key.pem',
'kube-scheduler.pem',
'kube-scheduler-key.pem',
'kube-controller-manager.pem',
'kube-controller-manager-key.pem',
{% for node in groups['kube-master'] %} {% for node in groups['kube-master'] %}
'admin-{{ node }}.pem', 'admin-{{ node }}.pem',
'admin-{{ node }}-key.pem', 'admin-{{ node }}-key.pem',
'apiserver.pem',
'apiserver-key.pem',
{% endfor %}]" {% endfor %}]"
my_master_certs: ['ca-key.pem', my_master_certs: ['ca-key.pem',
'admin-{{ inventory_hostname }}.pem', 'admin-{{ inventory_hostname }}.pem',
'admin-{{ inventory_hostname }}-key.pem', 'admin-{{ inventory_hostname }}-key.pem',
'apiserver.pem', 'apiserver.pem',
'apiserver-key.pem' 'apiserver-key.pem',
'kube-scheduler.pem',
'kube-scheduler-key.pem',
'kube-controller-manager.pem',
'kube-controller-manager-key.pem',
] ]
all_node_certs: "['ca.pem', all_node_certs: "['ca.pem',
{% for node in groups['k8s-cluster'] %} {% for node in groups['k8s-cluster'] %}