Merge pull request #1 from mceloud/master
add kubernetes engine
diff --git a/README.rst b/README.rst
index 1760c3e..866b6bb 100644
--- a/README.rst
+++ b/README.rst
@@ -65,6 +65,15 @@
- host: 10.0.175.103
name: etcd03
+run ETCD on k8s
+---------------
+
+.. code-block:: yaml
+
+ etcd:
+ server:
+ engine: kubernetes
+
Read more
=========
diff --git a/etcd/files/etcd.manifest b/etcd/files/etcd.manifest
new file mode 100644
index 0000000..10305e5
--- /dev/null
+++ b/etcd/files/etcd.manifest
@@ -0,0 +1,65 @@
+{%- from "etcd/map.jinja" import server with context %}
+{
+"apiVersion": "v1",
+"kind": "Pod",
+"metadata": {
+ "name":"etcd-server",
+ "namespace": "kube-system"
+},
+"spec":{
+"hostNetwork": true,
+"containers":[
+ {
+ "name": "etcd-container",
+ "image": "{{ server.registry }}/etcd:{{ server.version }}",
+ "resources": {
+ "requests": {
+ "cpu": "200m" }
+ },
+ "command": [
+ "/bin/sh",
+ "-c",
+ "/usr/local/bin/etcd --name {{ pillar.linux.system.name }} --initial-cluster-state new --initial-advertise-peer-urls http://{{ server.bind.host }}:2380 --listen-peer-urls http://{{ server.bind.host }}:2380 --advertise-client-urls http://{{ server.bind.host }}:4001 --listen-client-urls {%- if server.bind.host == '127.0.0.1' %}{% for member in server.members %} http://{{ member.host }}:4001{% endfor %}{% else %} http://{{ server.host }}:4001{% endif %},http://127.0.0.1:4001 --initial-cluster {% for member in server.members %}{{ member.name }}={%- if server.bind.host == '127.0.0.1' %}http://127.0.0.1:2380{% else %}http://{{ member.host }}:2380{% if not loop.last %},{% endif %}{% endif %}{% endfor %} --initial-cluster-token {{ server.token }} --data-dir /var/lib/etcd/default 1>>/var/log/etcd.log 2>&1"
+ ],
+ "livenessProbe": {
+ "httpGet": {
+ "host": "127.0.0.1",
+ "port": 4001,
+ "path": "/health"
+ },
+ "initialDelaySeconds": 15,
+ "timeoutSeconds": 15
+ },
+ "ports":[
+ { "name": "serverport",
+ "containerPort": 2380,
+ "hostPort": 2380
+ },{
+ "name": "clientport",
+ "containerPort": 4001,
+ "hostPort": 4001
+ }
+ ],
+ "volumeMounts": [
+ {"name": "varetcd",
+ "mountPath": "/var/lib/etcd",
+ "readOnly": false
+ },
+ {"name": "varlogetcd",
+ "mountPath": "/var/log/etcd.log",
+ "readOnly": false
+ }
+ ]
+ }
+],
+"volumes":[
+ { "name": "varetcd",
+ "hostPath": {
+ "path": "/var/lib/etcd"}
+ },
+ { "name": "varlogetcd",
+ "hostPath": {
+ "path": "/var/log/etcd.log"}
+ }
+]
+}}
\ No newline at end of file
diff --git a/etcd/server.sls b/etcd/server.sls
index 848affb..ec8c077 100644
--- a/etcd/server.sls
+++ b/etcd/server.sls
@@ -5,6 +5,31 @@
pkg.installed:
- names: {{ server.pkgs }}
+{%- if server.get('engine', 'systemd') == 'kubernetes' %}
+
+etcd_service:
+ service.dead:
+ - name: etcd
+ - enable: False
+
+/var/log/etcd.log:
+ file.managed:
+ - user: root
+ - group: root
+ - mode: 644
+
+/etc/kubernetes/manifests/etcd.manifest:
+ file.managed:
+ - source: salt://etcd/files/etcd.manifest
+ - template: jinja
+ - user: root
+ - group: root
+ - mode: 644
+ - makedirs: true
+ - dir_mode: 755
+
+{%- else %}
+
/etc/default/etcd:
file.managed:
- source: salt://etcd/files/default
@@ -20,3 +45,5 @@
- file: /etc/default/etcd
{%- endif %}
+
+{%- endif %}
diff --git a/metadata/service/server/proxy.yml b/metadata/service/server/proxy.yml
index 4de7a90..628bdc7 100644
--- a/metadata/service/server/proxy.yml
+++ b/metadata/service/server/proxy.yml
@@ -13,6 +13,6 @@
- host: ${_param:cluster_node01_address}
name: ${_param:cluster_node01_hostname}
- host: ${_param:cluster_node02_address}
- name: ${_param:cluster_node02_hostname}
+ name: ${_param:cluster_node02_hostname}
- host: ${_param:cluster_node03_address}
name: ${_param:cluster_node03_hostname}
\ No newline at end of file