Commit 13ba1776 authored by Marek Biskup's avatar Marek Biskup

kube-addon-update.sh

parent 51ffa203
# Cluster add-ons
Cluster add-ons are Services and Replication Controllers (with pods) that are
shipped with the kubernetes binaries and whose update policy is also consistent
with the update of kubernetes cluster.
On the clusterm the addons are kept in ```/etc/kubernetes/addons``` on the master node, in yaml files
(json is not supported at the moment).
Each add-on must specify the following label: ````kubernetes.io/cluster-service: true````.
Yaml files that do not define this label will be ignored.
The naming convention for Replication Controllers is
```<basename>-<version>```, where ```<basename>``` is the same in consecutive
versions and ```<version>``` changes when the component is updated
(```<version>``` must not contain ```-```). For instance,
```heapseter-controller-v1``` and ```heapster-controller-12``` are the
same controllers with two different versions, while ```heapseter-controller-v1```
and ```heapster-newcontroller-12``` are treated as two different applications.
For services it is just ```<basename>``` (with empty version number)
because we do not expect the service
name to change in consecutive versions. The naming convetion is important for add-on update.
# Add-on update
To update add-ons, just update the contents of ```/etc/kubernetes/addons```
directory with the desired definition of add-ons. Then the system will take care
of:
1. Removing the objects from the API server whose manifest was removed.
1. This is done for add-ons in the system that do not have a manifest file with the
same basename
1. Creating objects from new manifests
1. This is done for manifests that do not correspond to existing API objects
with the same basename
1. Updating objects whose basename is the samem but whose versions changed.
1. The update is currently performed by removing the old object and creating
the new one. In the future, rolling update of replication controllers will
be implemented to keep the add-on services up and running during update of add-on
pods.
1. Note that this cannot happen for Services as their version is always empty.
[![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/cluster/addons/README.md?pixel)]()
...@@ -5,6 +5,8 @@ metadata: ...@@ -5,6 +5,8 @@ metadata:
namespace: default namespace: default
labels: labels:
k8s-app: influxGrafana k8s-app: influxGrafana
kubernetes.io/cluster-service: "true"
kubernetes.io/name: "influxGrafana"
spec: spec:
ports: ports:
- name: http - name: http
......
addon-dir-delete:
file.absent:
- name: /etc/kubernetes/addons
addon-dir-create:
file.directory:
- name: /etc/kubernetes/addons
- user: root
- group: root
- mode: 0755
- require:
- file: addon-dir-delete
{% if pillar.get('enable_cluster_monitoring', '').lower() == 'influxdb' %} {% if pillar.get('enable_cluster_monitoring', '').lower() == 'influxdb' %}
/etc/kubernetes/addons/cluster-monitoring/influxdb: /etc/kubernetes/addons/cluster-monitoring/influxdb:
file.recurse: file.recurse:
...@@ -58,6 +71,13 @@ ...@@ -58,6 +71,13 @@
- group: root - group: root
- mode: 755 - mode: 755
/etc/kubernetes/kube-addon-update.sh:
file.managed:
- source: salt://kube-addons/kube-addon-update.sh
- user: root
- group: root
- mode: 755
{% if grains['os_family'] == 'RedHat' %} {% if grains['os_family'] == 'RedHat' %}
/usr/lib/systemd/system/kube-addons.service: /usr/lib/systemd/system/kube-addons.service:
...@@ -77,6 +97,16 @@ ...@@ -77,6 +97,16 @@
{% endif %} {% endif %}
# Stop kube-addons service each time salt is executed, just in case
# there was a modification of addons.
# Actually, this should be handled by watching file changes, but
# somehow it doesn't work.
service-kube-addon-stop:
service.dead:
- name: kube-addons
kube-addons: kube-addons:
service.running: service.running:
- enable: True - enable: True
- require:
- service: service-kube-addon-stop
...@@ -67,12 +67,7 @@ case "$1" in ...@@ -67,12 +67,7 @@ case "$1" in
esac esac
;; ;;
status) status)
if [ ! -e ${PIDFILE} ]; then status_of_proc -p $PIDFILE $KUBE_ADDONS_SH $NAME
exit 1
fi
pid=$(cat ${PIDFILE})
# Checks that ${pid} is running AND is us.
ps --no-headers ${pid} | grep ${SCRIPTNAME} > /dev/null || exit $?
;; ;;
restart|force-reload) restart|force-reload)
......
...@@ -81,7 +81,7 @@ function create-resource-from-string() { ...@@ -81,7 +81,7 @@ function create-resource-from-string() {
local -r config_string=$1; local -r config_string=$1;
local tries=$2; local tries=$2;
local -r delay=$3; local -r delay=$3;
local -r config_name=$1; local -r config_name=$4;
while [ ${tries} -gt 0 ]; do while [ ${tries} -gt 0 ]; do
echo "${config_string}" | ${KUBECTL} create -f - && \ echo "${config_string}" | ${KUBECTL} create -f - && \
echo "== Successfully started ${config_name} at $(date -Is)" && \ echo "== Successfully started ${config_name} at $(date -Is)" && \
...@@ -104,6 +104,7 @@ echo "== Kubernetes addon manager started at $(date -Is) ==" ...@@ -104,6 +104,7 @@ echo "== Kubernetes addon manager started at $(date -Is) =="
# at the same time as the services that use them. # at the same time as the services that use them.
# NOTE: needs to run as root to read this file. # NOTE: needs to run as root to read this file.
# Read each line in the csv file of tokens. # Read each line in the csv file of tokens.
# Expect errors when the script is started again.
while read line; do while read line; do
# Split each line into the token and username. # Split each line into the token and username.
IFS=',' read -a parts <<< "${line}" IFS=',' read -a parts <<< "${line}"
...@@ -120,22 +121,13 @@ for obj in $(find /etc/kubernetes/admission-controls \( -name \*.yaml -o -name \ ...@@ -120,22 +121,13 @@ for obj in $(find /etc/kubernetes/admission-controls \( -name \*.yaml -o -name \
echo "++ obj ${obj} is created ++" echo "++ obj ${obj} is created ++"
done done
for obj in $(find /etc/kubernetes/addons \( -name \*.yaml -o -name \*.json \)); do # Check if the configuration has changed recently - in case the user
start_addon ${obj} 100 10 & # created/updated/deleted the files on the master.
echo "++ addon ${obj} starting in pid $! ++" while true; do
done #kube-addon-update.sh must be deployed in the same directory as this file
noerrors="true" `dirname $0`/kube-addon-update.sh /etc/kubernetes/addons
for pid in $(jobs -p); do sleep 600
wait ${pid} || noerrors="false"
echo "++ pid ${pid} complete ++"
done done
if [ ${noerrors} == "true" ]; then
echo "== Kubernetes addon manager completed successfully at $(date -Is) =="
else
echo "== Kubernetes addon manager completed with errors at $(date -Is) =="
fi
# We stay around so that status checks by salt make it look like
# the service is good. (We could do this is other ways, but this
# is simple.)
sleep infinity
...@@ -25,6 +25,14 @@ ...@@ -25,6 +25,14 @@
{% endif %} {% endif %}
# Used to restart kube-master-addons service each time salt is run # Used to restart kube-master-addons service each time salt is run
# Actually, it doens't work (the service is not restarted),
# but master-addon service always terminates after it does it job,
# so it is (usually) not running and it will be started when
# salt is run.
# This salt state is not removed because there is a risk
# of introducing regression in 1.0. Please remove it afterwards.
# See also the salt config for kube-addons to see how to restart
# a service on demand.
master-docker-image-tags: master-docker-image-tags:
file.touch: file.touch:
- name: /srv/pillar/docker-images.sls - name: /srv/pillar/docker-images.sls
......
...@@ -67,12 +67,7 @@ case "$1" in ...@@ -67,12 +67,7 @@ case "$1" in
esac esac
;; ;;
status) status)
if [ ! -e ${PIDFILE} ]; then status_of_proc -p $PIDFILE $KUBE_MASTER_ADDONS_SH $NAME
exit 1
fi
pid=$(cat ${PIDFILE})
# Checks that ${pid} is running AND is us.
ps --no-headers ${pid} | grep ${SCRIPTNAME} > /dev/null || exit $?
;; ;;
restart|force-reload) restart|force-reload)
......
...@@ -38,3 +38,5 @@ while true; do ...@@ -38,3 +38,5 @@ while true; do
done; done;
# Now exit. After kube-push, salt will notice that the service is down and it
# will start it and new docker images will be loaded.
...@@ -2,7 +2,7 @@ logrotate: ...@@ -2,7 +2,7 @@ logrotate:
pkg: pkg:
- installed - installed
{% set logrotate_files = ['kube-scheduler', 'kube-proxy', 'kubelet', 'kube-apiserver', 'kube-controller-manager'] %} {% set logrotate_files = ['kube-scheduler', 'kube-proxy', 'kubelet', 'kube-apiserver', 'kube-controller-manager', 'kube-addons'] %}
{% for file in logrotate_files %} {% for file in logrotate_files %}
/etc/logrotate.d/{{ file }}: /etc/logrotate.d/{{ file }}:
file: file:
......
...@@ -30,6 +30,14 @@ monit: ...@@ -30,6 +30,14 @@ monit:
- mode: 644 - mode: 644
{% endif %} {% endif %}
/etc/monit/conf.d/kube-addons:
file:
- managed
- source: salt://monit/kube-addons
- user: root
- group: root
- mode: 644
/etc/monit/monit_watcher.sh: /etc/monit/monit_watcher.sh:
file.managed: file.managed:
- source: salt://monit/monit_watcher.sh - source: salt://monit/monit_watcher.sh
......
check process kube-addons with pidfile /var/run/kube-addons.pid
group kube-addons
start program = "/etc/init.d/kube-addons start"
stop program = "/etc/init.d/kube-addons stop"
if does not exist then restart
...@@ -86,7 +86,7 @@ func verifyExpectedRcsExistAndGetExpectedPods(c *client.Client) ([]string, error ...@@ -86,7 +86,7 @@ func verifyExpectedRcsExistAndGetExpectedPods(c *client.Client) ([]string, error
return nil, err return nil, err
} }
if len(rcList.Items) != 1 { if len(rcList.Items) != 1 {
return nil, fmt.Errorf("expected to find one replicat for RC with label %s but got %d", return nil, fmt.Errorf("expected to find one replica for RC with label %s but got %d",
rcLabel, len(rcList.Items)) rcLabel, len(rcList.Items))
} }
for _, rc := range rcList.Items { for _, rc := range rcList.Items {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment