VOL-569: Create kubernetes deployment configuration for each voltha service

This update:
- organizes all Voltha components under their own namespace, "voltha". If
  you have a script for deploying Voltha, then add namespace.yml at the top.
- adds host volume mounts for Consul's data and config directories
- fixes a bug in Envoy where it was aborting because it couldn't find Consul
  even though it was getting the Voltha assignments from Etcd.

Change-Id: I45eaf2d65428c0184df06971ce3797b9122d3055
diff --git a/envoy/go/envoyd/envoyd.go b/envoy/go/envoyd/envoyd.go
index 6523c90..b1a4067 100644
--- a/envoy/go/envoyd/envoyd.go
+++ b/envoy/go/envoyd/envoyd.go
@@ -145,7 +145,7 @@
 		time.Sleep(time.Duration(ec.waitTime) * time.Second)
 	}
 	if err != nil {
-		log.Printf("%s name resolution failed %d times gving up", serviceName, ec.retries)
+		log.Printf("%s name resolution failed %d times giving up", serviceName, ec.retries)
 	}
 	return
 }
@@ -623,9 +623,9 @@
 }
 
 func (ec * EnvoyControl) Initialize() (err error) {
-	// Resolve consul's virtual ip address
-	if err = ec.resolveServiceAddress(ec.consulSvcName); err != nil {
-		log.Fatal("Can't proceed without consul's vIP address: %s", err.Error())
+	// Resolve KV store's virtual ip address
+	if err = ec.resolveServiceAddress(ec.kvSvcName); err != nil {
+		log.Fatal("Can't proceed without KV store's vIP address: %s", err.Error())
 	}
 
 	// Resolve voltha's virtual ip address
@@ -638,7 +638,7 @@
 	}
 
 	if ec.httpDisabled == true && ec.httpsDisabled == true {
-		log.Printf("Cowardly refusing to disable both http and https, leavign them both enabled\n")
+		log.Printf("Cowardly refusing to disable both http and https, leaving them both enabled\n")
 	} else if ec.httpDisabled == true {
 		log.Printf("Diasabling http\n")
 		ec.envoyConfigTemplate = ec.envoyConfigTemplateNoHttp
@@ -663,7 +663,7 @@
 	log.Printf("KV-store %s at %s:%s", ec.kvStore, ec.kvSvcName, ec.kvPort)
 
 	if err = ec.Initialize(); err != nil {
-		log.Fatal("Envoy control initialization failed, aboring: %s", err.Error())
+		log.Fatal("Envoy control initialization failed, aborting: %s", err.Error())
 	}
 
 
diff --git a/k8s/consul.yml b/k8s/consul.yml
index 34b1fc8..b398b7a 100644
--- a/k8s/consul.yml
+++ b/k8s/consul.yml
@@ -2,6 +2,7 @@
 kind: Service
 metadata:
   name: consul
+  namespace: voltha
   labels:
     name: consul
 spec:
@@ -46,6 +47,7 @@
 kind: StatefulSet
 metadata:
   name: consul
+  namespace: voltha
 spec:
   serviceName: consul
   replicas: 3
@@ -70,27 +72,30 @@
       containers:
         - name: consul
           image: "consul:0.9.2"
+          volumeMounts:
+          - name: consul-config
+            mountPath: /consul/config
+          - name: consul-data
+            mountPath: /consul/data
           env:
-            - name: POD_IP
-              valueFrom:
-                fieldRef:
-                  fieldPath: status.podIP
             - name: NAMESPACE
               valueFrom:
                 fieldRef:
                   fieldPath: metadata.namespace
           args:
             - "agent"
-            - "-bind=0.0.0.0"
+            - "-server"
             - "-bootstrap-expect=3"
+            - "-config-dir=/consul/config"
+            - "-data-dir=/consul/data"
+            - "-bind=0.0.0.0"
+            - "-client=0.0.0.0"
+            - "-ui"
+            - "-raft-protocol=3"
+            - "-rejoin"
             - "-retry-join=consul-0.consul.$(NAMESPACE).svc.cluster.local"
             - "-retry-join=consul-1.consul.$(NAMESPACE).svc.cluster.local"
             - "-retry-join=consul-2.consul.$(NAMESPACE).svc.cluster.local"
-            - "-client=0.0.0.0"
-            - "-config-dir=/consul/config"
-            - "-data-dir=/consul/data"
-            - "-server"
-            - "-ui"
           lifecycle:
             preStop:
               exec:
@@ -117,3 +122,12 @@
               name: consuldns
             - containerPort: 8300
               name: server
+      volumes:
+      - name: consul-config
+        hostPath:
+          path: /cord/incubator/voltha/consul/config
+          type: Directory
+      - name: consul-data
+        hostPath:
+          path: /cord/incubator/voltha/consul/data
+          type: Directory
diff --git a/k8s/envoy_for_consul.yml b/k8s/envoy_for_consul.yml
index 5b6e7e4..8c02622 100644
--- a/k8s/envoy_for_consul.yml
+++ b/k8s/envoy_for_consul.yml
@@ -2,6 +2,7 @@
 kind: Service
 metadata:
   name: voltha
+  namespace: voltha
   labels:
     name: voltha
 spec:
@@ -26,6 +27,7 @@
 kind: Deployment
 metadata:
   name: voltha
+  namespace: voltha
 spec:
   replicas: 1
   template:
diff --git a/k8s/envoy_for_etcd.yml b/k8s/envoy_for_etcd.yml
index 2b7537c..af5c1f4 100644
--- a/k8s/envoy_for_etcd.yml
+++ b/k8s/envoy_for_etcd.yml
@@ -2,6 +2,7 @@
 kind: Service
 metadata:
   name: voltha
+  namespace: voltha
   labels:
     name: voltha
 spec:
@@ -26,6 +27,7 @@
 kind: Deployment
 metadata:
   name: voltha
+  namespace: voltha
 spec:
   replicas: 1
   template:
@@ -50,7 +52,7 @@
             - "-envoy-cfg-template=/envoy/voltha-grpc-proxy.template.json"
             - "-envoy-config=/envoy/voltha-grpc-proxy.json"
             - "-kv=etcd"
-            - "-kv-svc-name=etcd"
+            - "-kv-svc-name=etcd.$(NAMESPACE).svc.cluster.local"
             - "-kv-port=2379"
           ports:
             - containerPort: 8882
diff --git a/k8s/fluentd.yml b/k8s/fluentd.yml
index 0e4839b..c8bfa30 100644
--- a/k8s/fluentd.yml
+++ b/k8s/fluentd.yml
@@ -9,6 +9,7 @@
 kind: Service
 metadata:
   name: fluentdactv
+  namespace: voltha
 spec:
   clusterIP: None
   selector:
@@ -26,6 +27,7 @@
 kind: Deployment
 metadata:
   name: fluentdactv
+  namespace: voltha
 spec:
   replicas: 1
   template:
@@ -71,6 +73,7 @@
 kind: Service
 metadata:
   name: fluentdstby
+  namespace: voltha
 spec:
   clusterIP: None
   selector:
@@ -88,6 +91,7 @@
 kind: Deployment
 metadata:
   name: fluentdstby
+  namespace: voltha
 spec:
   replicas: 1
   template:
@@ -133,6 +137,7 @@
 kind: Service
 metadata:
   name: fluentd
+  namespace: voltha
 spec:
   clusterIP: None
   selector:
@@ -146,6 +151,7 @@
 kind: Deployment
 metadata:
   name: fluentd
+  namespace: voltha
 spec:
   replicas: 3
   template:
diff --git a/k8s/grafana.yml b/k8s/grafana.yml
index c6fa94d..10997b8 100644
--- a/k8s/grafana.yml
+++ b/k8s/grafana.yml
@@ -5,6 +5,7 @@
 kind: Service
 metadata:
   name: grafana
+  namespace: voltha
 spec:
   clusterIP: None
   selector:
@@ -35,6 +36,7 @@
 kind: Deployment
 metadata:
   name: grafana
+  namespace: voltha
 spec:
   replicas: 1
   template:
diff --git a/k8s/ingress/10-default-backend.yml b/k8s/ingress/10-default-backend.yml
index 64f6f58..38987aa 100644
--- a/k8s/ingress/10-default-backend.yml
+++ b/k8s/ingress/10-default-backend.yml
@@ -4,7 +4,7 @@
   name: default-http-backend
   labels:
     app: default-http-backend
-  namespace: ingress-nginx
+  namespace: voltha
 spec:
   replicas: 1
   template:
@@ -41,7 +41,7 @@
 kind: Service
 metadata:
   name: default-http-backend
-  namespace: ingress-nginx
+  namespace: voltha
   labels:
     app: default-http-backend
 spec:
diff --git a/k8s/ingress/20-configmap.yml b/k8s/ingress/20-configmap.yml
index 08e9101..28ff19b 100644
--- a/k8s/ingress/20-configmap.yml
+++ b/k8s/ingress/20-configmap.yml
@@ -2,6 +2,6 @@
 apiVersion: v1
 metadata:
   name: nginx-configuration
-  namespace: ingress-nginx
+  namespace: voltha
   labels:
     app: ingress-nginx
diff --git a/k8s/ingress/30-tcp-services-configmap.yml b/k8s/ingress/30-tcp-services-configmap.yml
index a963085..ffa28df 100644
--- a/k8s/ingress/30-tcp-services-configmap.yml
+++ b/k8s/ingress/30-tcp-services-configmap.yml
@@ -2,4 +2,4 @@
 apiVersion: v1
 metadata:
   name: tcp-services
-  namespace: ingress-nginx
+  namespace: voltha
diff --git a/k8s/ingress/40-udp-services-configmap.yml b/k8s/ingress/40-udp-services-configmap.yml
index 1870931..8b84b5e 100644
--- a/k8s/ingress/40-udp-services-configmap.yml
+++ b/k8s/ingress/40-udp-services-configmap.yml
@@ -2,4 +2,4 @@
 apiVersion: v1
 metadata:
   name: udp-services
-  namespace: ingress-nginx
+  namespace: voltha
diff --git a/k8s/ingress/50-rbac.yml b/k8s/ingress/50-rbac.yml
index 3018532..2ee80e1 100644
--- a/k8s/ingress/50-rbac.yml
+++ b/k8s/ingress/50-rbac.yml
@@ -2,7 +2,7 @@
 kind: ServiceAccount
 metadata:
   name: nginx-ingress-serviceaccount
-  namespace: ingress-nginx
+  namespace: voltha
 
 ---
 
@@ -64,7 +64,7 @@
 kind: Role
 metadata:
   name: nginx-ingress-role
-  namespace: ingress-nginx
+  namespace: voltha
 rules:
   - apiGroups:
       - ""
@@ -107,7 +107,7 @@
 kind: RoleBinding
 metadata:
   name: nginx-ingress-role-nisa-binding
-  namespace: ingress-nginx
+  namespace: voltha
 roleRef:
   apiGroup: rbac.authorization.k8s.io
   kind: Role
@@ -115,7 +115,7 @@
 subjects:
   - kind: ServiceAccount
     name: nginx-ingress-serviceaccount
-    namespace: ingress-nginx
+    namespace: voltha
 
 ---
 
@@ -130,4 +130,4 @@
 subjects:
   - kind: ServiceAccount
     name: nginx-ingress-serviceaccount
-    namespace: ingress-nginx
+    namespace: voltha
diff --git a/k8s/ingress/60-cluster-ingress-nginx.yml b/k8s/ingress/60-cluster-ingress-nginx.yml
index a70a7fa..5b86979 100644
--- a/k8s/ingress/60-cluster-ingress-nginx.yml
+++ b/k8s/ingress/60-cluster-ingress-nginx.yml
@@ -2,7 +2,7 @@
 kind: Deployment
 metadata:
   name: nginx-ingress-controller
-  namespace: ingress-nginx 
+  namespace: voltha
 spec:
   replicas: 1
   selector:
diff --git a/k8s/ingress/70-service-ingress-nginx.yml b/k8s/ingress/70-service-ingress-nginx.yml
index 9a1cfa9..da11d04 100644
--- a/k8s/ingress/70-service-ingress-nginx.yml
+++ b/k8s/ingress/70-service-ingress-nginx.yml
@@ -2,7 +2,7 @@
 kind: Service
 metadata:
   name: ingress-nginx
-  namespace: ingress-nginx
+  namespace: voltha
 spec:
   type: NodePort
   selector:
diff --git a/k8s/ingress/80-ingress.yml b/k8s/ingress/80-ingress.yml
index c665801..c2129c1 100644
--- a/k8s/ingress/80-ingress.yml
+++ b/k8s/ingress/80-ingress.yml
@@ -2,6 +2,7 @@
 kind: Ingress
 metadata:
   name: voltha-ingress
+  namespace: voltha
   annotations:
     kubernetes.io/ingress.class: "nginx"
     ingress.kubernetes.io/rewrite-target: /
diff --git a/k8s/kafka.yml b/k8s/kafka.yml
index a8db827..00f8441 100644
--- a/k8s/kafka.yml
+++ b/k8s/kafka.yml
@@ -2,6 +2,7 @@
 kind: Service
 metadata:
   name: kafka
+  namespace: voltha
 spec:
   clusterIP: None
   selector:
@@ -15,6 +16,7 @@
 kind: StatefulSet
 metadata:
   name: kafka
+  namespace: voltha
 spec:
   serviceName: kafka
   replicas: 3
diff --git a/k8s/namespace.yml b/k8s/namespace.yml
new file mode 100644
index 0000000..5fda4a1
--- /dev/null
+++ b/k8s/namespace.yml
@@ -0,0 +1,9 @@
+#
+# Observation:
+#    It appears that when a namespace is created, Kubernetes creates
+#    a ServiceAccount called "default" for that new namespace.
+#
+apiVersion: v1
+kind: Namespace
+metadata:
+  name: voltha
diff --git a/k8s/netconf.yml b/k8s/netconf.yml
index 125e3e1..d5d4343 100644
--- a/k8s/netconf.yml
+++ b/k8s/netconf.yml
@@ -2,6 +2,7 @@
 kind: Service
 metadata:
   name: netconf
+  namespace: voltha
 spec:
   selector:
     app: netconf
@@ -14,6 +15,7 @@
 kind: Deployment
 metadata:
   name: netconf
+  namespace: voltha
 spec:
   replicas: 3
   template:
diff --git a/k8s/ofagent.yml b/k8s/ofagent.yml
index 7598d0b..ec06664 100644
--- a/k8s/ofagent.yml
+++ b/k8s/ofagent.yml
@@ -2,6 +2,7 @@
 kind: Deployment
 metadata:
   name: ofagent
+  namespace: voltha
 spec:
   replicas: 3
   template:
diff --git a/k8s/operator/etcd/cluster_role_binding.yml b/k8s/operator/etcd/cluster_role_binding.yml
index 707463f..ce32037 100644
--- a/k8s/operator/etcd/cluster_role_binding.yml
+++ b/k8s/operator/etcd/cluster_role_binding.yml
@@ -9,5 +9,4 @@
 subjects:
 - kind: ServiceAccount
   name: default
-  namespace: default
-
+  namespace: voltha
diff --git a/k8s/operator/etcd/etcd_cluster.yml b/k8s/operator/etcd/etcd_cluster.yml
index af6aa03..904588e 100644
--- a/k8s/operator/etcd/etcd_cluster.yml
+++ b/k8s/operator/etcd/etcd_cluster.yml
@@ -1,7 +1,8 @@
 apiVersion: "etcd.database.coreos.com/v1beta2"
 kind: "EtcdCluster"
 metadata:
-  name: "etcd"
+  name: etcd
+  namespace: voltha
 spec:
   size: 3
   version: "3.2.9"
diff --git a/k8s/operator/etcd/operator.yml b/k8s/operator/etcd/operator.yml
index 4e6d679..7e51944 100644
--- a/k8s/operator/etcd/operator.yml
+++ b/k8s/operator/etcd/operator.yml
@@ -2,6 +2,7 @@
 kind: Deployment
 metadata:
   name: etcd-operator
+  namespace: voltha
 spec:
   replicas: 1
   template:
diff --git a/k8s/stats.yml b/k8s/stats.yml
index 13c4655..91202ff 100644
--- a/k8s/stats.yml
+++ b/k8s/stats.yml
@@ -5,6 +5,7 @@
 kind: Deployment
 metadata:
   name: dashd
+  namespace: voltha
 spec:
   replicas: 1
   template:
@@ -35,6 +36,7 @@
 kind: Deployment
 metadata:
   name: shovel
+  namespace: voltha
 spec:
   replicas: 1
   template:
diff --git a/k8s/vcli.yml b/k8s/vcli.yml
index bcb7b20..e1563ab 100644
--- a/k8s/vcli.yml
+++ b/k8s/vcli.yml
@@ -2,6 +2,7 @@
 kind: Service
 metadata:
   name: vcli
+  namespace: voltha
   labels:
     name: vcli
 spec:
@@ -16,6 +17,7 @@
 kind: Deployment
 metadata:
   name: vcli
+  namespace: voltha
 spec:
   replicas: 2
   template:
diff --git a/k8s/vcore_for_consul.yml b/k8s/vcore_for_consul.yml
index 260c21e..e3ed245 100644
--- a/k8s/vcore_for_consul.yml
+++ b/k8s/vcore_for_consul.yml
@@ -2,6 +2,7 @@
 kind: Service
 metadata:
   name: vcore
+  namespace: voltha
   labels:
     name: vcore
 spec:
@@ -23,6 +24,7 @@
 kind: Deployment
 metadata:
   name: vcore
+  namespace: voltha
 spec:
   replicas: 3
   template:
@@ -59,4 +61,4 @@
         - "--interface=eth1"
         - "--backend=consul"
         - "--pon-subnet=10.38.0.0/12"
-        - "--ponsim-comm=grpc"
\ No newline at end of file
+        - "--ponsim-comm=grpc"
diff --git a/k8s/vcore_for_etcd.yml b/k8s/vcore_for_etcd.yml
index edb6a29..23ca300 100644
--- a/k8s/vcore_for_etcd.yml
+++ b/k8s/vcore_for_etcd.yml
@@ -2,6 +2,7 @@
 kind: Service
 metadata:
   name: vcore
+  namespace: voltha
   labels:
     name: vcore
 spec:
@@ -23,6 +24,7 @@
 kind: Deployment
 metadata:
   name: vcore
+  namespace: voltha
 spec:
   replicas: 3
   template:
diff --git a/k8s/zookeeper.yml b/k8s/zookeeper.yml
index 3ef7b3d..2f3ceba 100644
--- a/k8s/zookeeper.yml
+++ b/k8s/zookeeper.yml
@@ -2,6 +2,7 @@
 kind: Service
 metadata:
   name: zoo1
+  namespace: voltha
 spec:
   clusterIP: None
   selector:
@@ -21,6 +22,7 @@
 kind: Service
 metadata:
   name: zoo2
+  namespace: voltha
 spec:
   clusterIP: None
   selector:
@@ -40,6 +42,7 @@
 kind: Service
 metadata:
   name: zoo3
+  namespace: voltha
 spec:
   clusterIP: None
   selector:
@@ -59,6 +62,7 @@
 kind: StatefulSet
 metadata:
   name: zookeeper1
+  namespace: voltha
 spec:
   serviceName: zoo1
   replicas: 1
@@ -96,6 +100,7 @@
 kind: StatefulSet
 metadata:
   name: zookeeper2
+  namespace: voltha
 spec:
   serviceName: zoo2
   replicas: 1
@@ -133,6 +138,7 @@
 kind: StatefulSet
 metadata:
   name: zookeeper3
+  namespace: voltha
 spec:
   serviceName: zoo3
   replicas: 1