VOL-569: Create kubernetes deployment configuration for each voltha service
This update adds kubernetes deployment files for etcd. These files are not
yet production-ready; for example, the etcd deployment will have to be
augmented to support persistent storage. The files do work and enable the
deployment of the envoy and vcore services on kubernetes.
Change-Id: I6ba8e5557b295a4f759d8f359024238fcf387d6a
diff --git a/k8s/operator/etcd/README.md b/k8s/operator/etcd/README.md
new file mode 100644
index 0000000..75cad82
--- /dev/null
+++ b/k8s/operator/etcd/README.md
@@ -0,0 +1,36 @@
+# How to Deploy an Etcd Cluster on Kubernetes
+
+There may be several ways to deploy an etcd cluster. The following is an example of deploying a cluster using an etcd operator; it was tested on kubernetes 1.8.5. Information about the etcd operator and how to deploy it seems to change frequently; check out the following links:
+* https://coreos.com/blog/introducing-the-etcd-operator.html
+* https://github.com/coreos/etcd-operator/blob/master/README.md
+
+The procedure uses the default namespace and the default ServiceAccount. For voltha we'd likely want to use a voltha-specific namespace and ServiceAccount.
+
+Another issue to explore is role scope. Do we create a role global to the cluster, i.e. ClusterRole, or do we create a more constrained Role.
+
+Set up basic RBAC rules for the etcd operator:
+
+1. Create a ClusterRole called etcd-operator.
+```
+kubectl create -f cluster_role.yml
+kubectl get clusterrole
+```
+2. Create a ClusterRoleBinding that binds the default service account in the default namespace to the new role.
+```
+kubectl create -f cluster_role_binding.yml
+kubectl get clusterrolebinding
+```
+Deploy the etcd operator.
+```
+kubectl create -f operator.yml
+```
+The etcd operator will automatically create a CustomResourceDefinition (CRD).
+```
+$ kubectl get customresourcedefinitions
+NAME AGE
+etcdclusters.etcd.database.coreos.com 4m
+```
+Deploy the etcd cluster.
+```
+kubectl create -f etcd_cluster.yml
+```
\ No newline at end of file
diff --git a/k8s/operator/etcd/cluster_role.yml b/k8s/operator/etcd/cluster_role.yml
new file mode 100644
index 0000000..480de28
--- /dev/null
+++ b/k8s/operator/etcd/cluster_role.yml
@@ -0,0 +1,40 @@
+apiVersion: rbac.authorization.k8s.io/v1beta1
+kind: ClusterRole
+metadata:
+ name: etcd-operator
+rules:
+- apiGroups:
+ - etcd.database.coreos.com
+ resources:
+ - etcdclusters
+ verbs:
+ - "*"
+- apiGroups:
+ - apiextensions.k8s.io
+ resources:
+ - customresourcedefinitions
+ verbs:
+ - "*"
+- apiGroups:
+ - storage.k8s.io
+ resources:
+ - storageclasses
+ verbs:
+ - "*"
+- apiGroups:
+ - ""
+ resources:
+ - pods
+ - services
+ - endpoints
+ - persistentvolumeclaims
+ - events
+ verbs:
+ - "*"
+- apiGroups:
+ - apps
+ resources:
+ - deployments
+ verbs:
+ - "*"
+
diff --git a/k8s/operator/etcd/cluster_role_binding.yml b/k8s/operator/etcd/cluster_role_binding.yml
new file mode 100644
index 0000000..707463f
--- /dev/null
+++ b/k8s/operator/etcd/cluster_role_binding.yml
@@ -0,0 +1,13 @@
+apiVersion: rbac.authorization.k8s.io/v1beta1
+kind: ClusterRoleBinding
+metadata:
+ name: etcd-operator
+roleRef:
+ apiGroup: rbac.authorization.k8s.io
+ kind: ClusterRole
+ name: etcd-operator
+subjects:
+- kind: ServiceAccount
+ name: default
+ namespace: default
+
diff --git a/k8s/operator/etcd/etcd_cluster.yml b/k8s/operator/etcd/etcd_cluster.yml
new file mode 100644
index 0000000..af6aa03
--- /dev/null
+++ b/k8s/operator/etcd/etcd_cluster.yml
@@ -0,0 +1,8 @@
+apiVersion: "etcd.database.coreos.com/v1beta2"
+kind: "EtcdCluster"
+metadata:
+ name: "etcd"
+spec:
+ size: 3
+ version: "3.2.9"
+
diff --git a/k8s/operator/etcd/operator.yml b/k8s/operator/etcd/operator.yml
new file mode 100644
index 0000000..4e6d679
--- /dev/null
+++ b/k8s/operator/etcd/operator.yml
@@ -0,0 +1,26 @@
+apiVersion: extensions/v1beta1
+kind: Deployment
+metadata:
+ name: etcd-operator
+spec:
+ replicas: 1
+ template:
+ metadata:
+ labels:
+ name: etcd-operator
+ spec:
+ containers:
+ - name: etcd-operator
+ image: quay.io/coreos/etcd-operator:v0.7.2
+ command:
+ - etcd-operator
+ env:
+ - name: MY_POD_NAMESPACE
+ valueFrom:
+ fieldRef:
+ fieldPath: metadata.namespace
+ - name: MY_POD_NAME
+ valueFrom:
+ fieldRef:
+ fieldPath: metadata.name
+