run etcd as docker container
This commit is contained in:
parent
836483388f
commit
18f2cc9d48
13 changed files with 23 additions and 196 deletions
|
@ -42,6 +42,7 @@
|
||||||
- name: Check configured hostname
|
- name: Check configured hostname
|
||||||
shell: hostname
|
shell: hostname
|
||||||
register: configured_hostname
|
register: configured_hostname
|
||||||
|
changed_when: false
|
||||||
|
|
||||||
- name: Assign inventory name to unconfigured hostnames
|
- name: Assign inventory name to unconfigured hostnames
|
||||||
shell: sh -c "echo \"{{inventory_hostname}}\" > /etc/hostname; hostname \"{{inventory_hostname}}\""
|
shell: sh -c "echo \"{{inventory_hostname}}\" > /etc/hostname; hostname \"{{inventory_hostname}}\""
|
||||||
|
|
|
@ -2,9 +2,5 @@
|
||||||
etcd_version: v3.0.1
|
etcd_version: v3.0.1
|
||||||
etcd_bin_dir: "{{ local_release_dir }}/etcd/etcd-{{ etcd_version }}-linux-amd64/"
|
etcd_bin_dir: "{{ local_release_dir }}/etcd/etcd-{{ etcd_version }}-linux-amd64/"
|
||||||
|
|
||||||
# Possible values: host, docker
|
|
||||||
etcd_deployment_type: "host"
|
|
||||||
|
|
||||||
|
|
||||||
etcd_image_repo: "quay.io/coreos/etcd"
|
etcd_image_repo: "quay.io/coreos/etcd"
|
||||||
etcd_image_tag: "{{ etcd_version }}"
|
etcd_image_tag: "{{ etcd_version }}"
|
||||||
|
|
|
@ -19,4 +19,4 @@
|
||||||
- name: reload etcd
|
- name: reload etcd
|
||||||
service:
|
service:
|
||||||
name: etcd
|
name: etcd
|
||||||
state: "{{ 'restarted' if etcd_deployment_type == 'host' else 'reloaded' }}"
|
state: reloaded
|
||||||
|
|
|
@ -3,8 +3,6 @@ dependencies:
|
||||||
- role: adduser
|
- role: adduser
|
||||||
user: "{{ addusers.etcd }}"
|
user: "{{ addusers.etcd }}"
|
||||||
when: ansible_os_family != 'CoreOS'
|
when: ansible_os_family != 'CoreOS'
|
||||||
- role: download
|
- role: kubernetes/common
|
||||||
file: "{{ downloads.etcd }}"
|
|
||||||
when: etcd_deployment_type == "host"
|
|
||||||
- role: docker
|
- role: docker
|
||||||
when: (ansible_os_family != "CoreOS" and etcd_deployment_type == "docker")
|
when: ansible_os_family != "CoreOS"
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
|
|
||||||
- name: Configure | Copy etcd.service systemd file
|
- name: Configure | Copy etcd.service systemd file
|
||||||
template:
|
template:
|
||||||
src: "etcd-{{ etcd_deployment_type }}.service.j2"
|
src: "etcd.service.j2"
|
||||||
dest: /etc/systemd/system/etcd.service
|
dest: /etc/systemd/system/etcd.service
|
||||||
backup: yes
|
backup: yes
|
||||||
when: ansible_service_mgr == "systemd"
|
when: ansible_service_mgr == "systemd"
|
||||||
|
@ -20,7 +20,7 @@
|
||||||
|
|
||||||
- name: Configure | Write etcd initd script
|
- name: Configure | Write etcd initd script
|
||||||
template:
|
template:
|
||||||
src: "deb-etcd-{{ etcd_deployment_type }}.initd.j2"
|
src: "deb-etcd.initd.j2"
|
||||||
dest: /etc/init.d/etcd
|
dest: /etc/init.d/etcd
|
||||||
owner: root
|
owner: root
|
||||||
mode: 0755
|
mode: 0755
|
||||||
|
|
|
@ -1,39 +0,0 @@
|
||||||
---
|
|
||||||
- name: Install | Copy etcd binary from downloaddir
|
|
||||||
command: rsync -piu "{{ etcd_bin_dir }}/etcd" "{{ bin_dir }}/etcd"
|
|
||||||
when: etcd_deployment_type == "host"
|
|
||||||
register: etcd_copy
|
|
||||||
changed_when: false
|
|
||||||
|
|
||||||
- name: Install | Copy etcdctl binary from downloaddir
|
|
||||||
command: rsync -piu "{{ etcd_bin_dir }}/etcdctl" "{{ bin_dir }}/etcdctl"
|
|
||||||
when: etcd_deployment_type == "host"
|
|
||||||
changed_when: false
|
|
||||||
|
|
||||||
#Plan A: no docker-py deps
|
|
||||||
- name: Install | Copy etcdctl binary from container
|
|
||||||
command: sh -c "/usr/bin/docker rm -f etcdctl-binarycopy;
|
|
||||||
/usr/bin/docker create --name etcdctl-binarycopy {{ etcd_image_repo }}:{{ etcd_image_tag }} &&
|
|
||||||
/usr/bin/docker cp etcdctl-binarycopy:{{ etcd_container_bin_dir }}etcdctl {{ bin_dir }}/etcdctl &&
|
|
||||||
/usr/bin/docker rm -f etcdctl-binarycopy"
|
|
||||||
when: etcd_deployment_type == "docker"
|
|
||||||
changed_when: false
|
|
||||||
|
|
||||||
#Plan B: looks nicer, but requires docker-py on all hosts:
|
|
||||||
#- name: Install | Set up etcd-binarycopy container
|
|
||||||
# docker:
|
|
||||||
# name: etcd-binarycopy
|
|
||||||
# state: present
|
|
||||||
# image: "{{ etcd_image_repo }}:{{ etcd_image_tag }}"
|
|
||||||
# when: etcd_deployment_type == "docker"
|
|
||||||
#
|
|
||||||
#- name: Install | Copy etcdctl from etcd-binarycopy container
|
|
||||||
# command: /usr/bin/docker cp "etcd-binarycopy:{{ etcd_container_bin_dir }}etcdctl" "{{ bin_dir }}/etcdctl"
|
|
||||||
# when: etcd_deployment_type == "docker"
|
|
||||||
#
|
|
||||||
#- name: Install | Clean up etcd-binarycopy container
|
|
||||||
# docker:
|
|
||||||
# name: etcd-binarycopy
|
|
||||||
# state: absent
|
|
||||||
# image: "{{ etcd_image_repo }}:{{ etcd_image_tag }}"
|
|
||||||
# when: etcd_deployment_type == "docker"
|
|
|
@ -1,14 +1,18 @@
|
||||||
---
|
---
|
||||||
- include: set_facts.yml
|
- include: set_facts.yml
|
||||||
- include: install.yml
|
|
||||||
- include: set_cluster_health.yml
|
|
||||||
- include: configure.yml
|
|
||||||
- include: refresh_config.yml
|
|
||||||
|
|
||||||
- name: Restart etcd if binary changed
|
- name: Install | Copy etcdctl binary from container
|
||||||
command: /bin/true
|
command: sh -c "/usr/bin/docker rm -f etcdctl-binarycopy;
|
||||||
notify: restart etcd
|
/usr/bin/docker create --name etcdctl-binarycopy {{ etcd_image_repo }}:{{ etcd_image_tag }} &&
|
||||||
when: etcd_deployment_type == "host" and etcd_copy.stdout_lines
|
/usr/bin/docker cp etcdctl-binarycopy:{{ etcd_container_bin_dir }}etcdctl {{ bin_dir }}/etcdctl &&
|
||||||
|
/usr/bin/docker rm -f etcdctl-binarycopy"
|
||||||
|
changed_when: false
|
||||||
|
|
||||||
|
- include: set_cluster_health.yml
|
||||||
|
|
||||||
|
- include: configure.yml
|
||||||
|
|
||||||
|
- include: refresh_config.yml
|
||||||
|
|
||||||
# Reload systemd before starting service
|
# Reload systemd before starting service
|
||||||
- meta: flush_handlers
|
- meta: flush_handlers
|
||||||
|
|
|
@ -1,19 +1,23 @@
|
||||||
---
|
---
|
||||||
- set_fact: etcd_access_address="{{ access_ip | default(ip | default(ansible_default_ipv4['address'])) }}"
|
- set_fact: etcd_access_address="{{access_ip | default(ip | default(ansible_default_ipv4['address']))}}"
|
||||||
- set_fact: etcd_peer_url="http://{{ etcd_access_address }}:2380"
|
- set_fact: etcd_peer_url="http://{{ etcd_access_address }}:2380"
|
||||||
- set_fact: etcd_client_url="http://{{ etcd_access_address }}:2379"
|
- set_fact: etcd_client_url="http://{{ etcd_access_address }}:2379"
|
||||||
|
|
||||||
- set_fact:
|
- set_fact:
|
||||||
etcd_access_addresses: |-
|
etcd_access_addresses: |-
|
||||||
{% for item in groups['etcd'] -%}
|
{% for item in groups['etcd'] -%}
|
||||||
http://{{ hostvars[item].etcd_access_address }}:2379{% if not loop.last %},{% endif %}
|
http://{{ hostvars[item].etcd_access_address }}:2379{% if not loop.last %},{% endif %}
|
||||||
{%- endfor %}
|
{%- endfor %}
|
||||||
|
|
||||||
- set_fact:
|
- set_fact:
|
||||||
etcd_member_name: |-
|
etcd_member_name: |-
|
||||||
{% for host in groups['etcd'] %}
|
{% for host in groups['etcd'] %}
|
||||||
{% if inventory_hostname == host %}{{"etcd"+loop.index|string }}{% endif %}
|
{% if inventory_hostname == host %}{{"etcd"+loop.index|string }}{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
- set_fact:
|
- set_fact:
|
||||||
is_etcd_master: "{{ inventory_hostname in groups['etcd'] }}"
|
is_etcd_master: "{{ inventory_hostname in groups['etcd'] }}"
|
||||||
|
|
||||||
- set_fact:
|
- set_fact:
|
||||||
etcd_after_v3: etcd_version | version_compare("v3.0.0", ">=")
|
etcd_after_v3: etcd_version | version_compare("v3.0.0", ">=")
|
||||||
- set_fact:
|
- set_fact:
|
||||||
|
|
|
@ -1,114 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
set -a
|
|
||||||
|
|
||||||
### BEGIN INIT INFO
|
|
||||||
# Provides: etcd
|
|
||||||
# Required-Start: $local_fs $network $syslog
|
|
||||||
# Required-Stop:
|
|
||||||
# Default-Start: 2 3 4 5
|
|
||||||
# Default-Stop: 0 1 6
|
|
||||||
# Short-Description: etcd distributed k/v store
|
|
||||||
# Description:
|
|
||||||
# etcd is a distributed, consistent key-value store for shared configuration and service discovery
|
|
||||||
### END INIT INFO
|
|
||||||
|
|
||||||
PATH=/sbin:/usr/sbin:/bin:/usr/bin
|
|
||||||
DESC="etcd k/v store"
|
|
||||||
NAME=etcd
|
|
||||||
DAEMON={{ bin_dir }}/etcd
|
|
||||||
{% if is_etcd_master %}
|
|
||||||
DAEMON_ARGS=""
|
|
||||||
{% else %}
|
|
||||||
DAEMON_ARGS="--proxy on"
|
|
||||||
{% endif %}
|
|
||||||
SCRIPTNAME=/etc/init.d/$NAME
|
|
||||||
DAEMON_USER=etcd
|
|
||||||
STOP_SCHEDULE="${STOP_SCHEDULE:-QUIT/5/TERM/5/KILL/5}"
|
|
||||||
PID=/var/run/etcd.pid
|
|
||||||
|
|
||||||
# Exit if the binary is not present
|
|
||||||
[ -x "$DAEMON" ] || exit 0
|
|
||||||
|
|
||||||
# Read configuration variable file if it is present
|
|
||||||
[ -f /etc/etcd.env ] && . /etc/etcd.env
|
|
||||||
|
|
||||||
# Define LSB log_* functions.
|
|
||||||
# Depend on lsb-base (>= 3.2-14) to ensure that this file is present
|
|
||||||
# and status_of_proc is working.
|
|
||||||
. /lib/lsb/init-functions
|
|
||||||
|
|
||||||
do_status()
|
|
||||||
{
|
|
||||||
status_of_proc -p $PID "$DAEMON" "$NAME" && exit 0 || exit $?
|
|
||||||
}
|
|
||||||
|
|
||||||
# Function that starts the daemon/service
|
|
||||||
#
|
|
||||||
do_start()
|
|
||||||
{
|
|
||||||
start-stop-daemon --background --start --quiet --make-pidfile --pidfile $PID --user $DAEMON_USER --exec $DAEMON -- \
|
|
||||||
$DAEMON_ARGS \
|
|
||||||
|| return 2
|
|
||||||
}
|
|
||||||
|
|
||||||
#
|
|
||||||
# Function that stops the daemon/service
|
|
||||||
#
|
|
||||||
do_stop()
|
|
||||||
{
|
|
||||||
start-stop-daemon --stop --quiet --retry=$STOP_SCHEDULE --pidfile $PID --name $NAME
|
|
||||||
RETVAL="$?"
|
|
||||||
|
|
||||||
sleep 1
|
|
||||||
return "$RETVAL"
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
case "$1" in
|
|
||||||
start)
|
|
||||||
log_daemon_msg "Starting $DESC" "$NAME"
|
|
||||||
do_start
|
|
||||||
case "$?" in
|
|
||||||
0|1) log_end_msg 0 || exit 0 ;;
|
|
||||||
2) log_end_msg 1 || exit 1 ;;
|
|
||||||
esac
|
|
||||||
;;
|
|
||||||
stop)
|
|
||||||
log_daemon_msg "Stopping $DESC" "$NAME"
|
|
||||||
if do_stop; then
|
|
||||||
log_end_msg 0
|
|
||||||
else
|
|
||||||
log_failure_msg "Can't stop etcd"
|
|
||||||
log_end_msg 1
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
status)
|
|
||||||
if do_status; then
|
|
||||||
log_end_msg 0
|
|
||||||
else
|
|
||||||
log_failure_msg "etcd is not running"
|
|
||||||
log_end_msg 1
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
|
|
||||||
restart|force-reload)
|
|
||||||
log_daemon_msg "Restarting $DESC" "$NAME"
|
|
||||||
if do_stop; then
|
|
||||||
if do_start; then
|
|
||||||
log_end_msg 0
|
|
||||||
exit 0
|
|
||||||
else
|
|
||||||
rc="$?"
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
rc="$?"
|
|
||||||
fi
|
|
||||||
log_failure_msg "Can't restart etcd"
|
|
||||||
log_end_msg ${rc}
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
|
|
||||||
exit 3
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
|
@ -1,18 +0,0 @@
|
||||||
[Unit]
|
|
||||||
Description=etcd
|
|
||||||
|
|
||||||
|
|
||||||
[Service]
|
|
||||||
User=etcd
|
|
||||||
EnvironmentFile=/etc/etcd.env
|
|
||||||
{% if inventory_hostname in groups['etcd'] %}
|
|
||||||
ExecStart={{ bin_dir }}/etcd
|
|
||||||
{% else %}
|
|
||||||
ExecStart={{ bin_dir }}/etcd -proxy on
|
|
||||||
{% endif %}
|
|
||||||
Restart=always
|
|
||||||
RestartSec=10s
|
|
||||||
LimitNOFILE=40000
|
|
||||||
|
|
||||||
[Install]
|
|
||||||
WantedBy=multi-user.target
|
|
|
@ -5,11 +5,6 @@
|
||||||
state: latest
|
state: latest
|
||||||
when: ansible_os_family != "CoreOS" and kpm_packages | length > 0
|
when: ansible_os_family != "CoreOS" and kpm_packages | length > 0
|
||||||
|
|
||||||
# workaround for the error "cannot import name IncompleteRead"
|
|
||||||
- name: Upgrade pip
|
|
||||||
command: easy_install -U pip
|
|
||||||
changed_when: false
|
|
||||||
|
|
||||||
- name: install kpm
|
- name: install kpm
|
||||||
pip:
|
pip:
|
||||||
name: "kpm"
|
name: "kpm"
|
||||||
|
|
Loading…
Reference in a new issue