This is an automated email from the ASF dual-hosted git repository.

kezhenxu94 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/skywalking-showcase.git

commit 402da4a9b54df9972ea1bb4dec2813612a419768
Author: kezhenxu94 <[email protected]>
AuthorDate: Mon Nov 8 12:38:42 2021 +0800

    Add Kubernetes cluster feature
---
 .../permissions.yaml                               | 16 ++++---
 .../resources.yaml                                 | 55 +++++++++++++++++++++-
 .../kubernetes/feature-single-node/resources.yaml  |  1 -
 .../kubernetes/feature-so11y/permissions.yaml      |  2 +-
 4 files changed, 64 insertions(+), 10 deletions(-)

diff --git a/deploy/platform/kubernetes/feature-so11y/permissions.yaml 
b/deploy/platform/kubernetes/feature-cluster/permissions.yaml
similarity index 73%
copy from deploy/platform/kubernetes/feature-so11y/permissions.yaml
copy to deploy/platform/kubernetes/feature-cluster/permissions.yaml
index 0aa91d7..6d36eee 100644
--- a/deploy/platform/kubernetes/feature-so11y/permissions.yaml
+++ b/deploy/platform/kubernetes/feature-cluster/permissions.yaml
@@ -19,29 +19,33 @@
 apiVersion: v1
 kind: ServiceAccount
 metadata:
-  name: otel-sa-so11y
+  name: skywalking-sa-cluster
 
 ---
 kind: ClusterRole
 apiVersion: rbac.authorization.k8s.io/v1
 metadata:
-  name: otel-role-so11y
+  name: skywalking-sa-cluster-role
 rules:
   - apiGroups: [ "" ]
     resources:
-      - "pods" # @feature: so11y; OpenTelemetry needs to read OAP pods 
information to get OAP details
+      - "pods" # @feature: cluster; OAP needs to read other OAP Pods 
information to form a cluster
+    verbs: [ "get", "watch", "list" ]
+  - apiGroups: [ "batch" ]
+    resources:
+      - "jobs" # @feature: cluster; OAP needs to wait for the init job to 
complete
     verbs: [ "get", "watch", "list" ]
 
 ---
 apiVersion: rbac.authorization.k8s.io/v1
 kind: ClusterRoleBinding
 metadata:
-  name: otel-role-binding-so11y
+  name: skywalking-sa-cluster-role-binding
 roleRef:
   apiGroup: rbac.authorization.k8s.io
   kind: ClusterRole
-  name: otel-role-so11y
+  name: skywalking-sa-cluster-role
 subjects:
   - kind: ServiceAccount
-    name: otel-sa-so11y
+    name: skywalking-sa-cluster
     namespace: default
diff --git a/deploy/platform/kubernetes/feature-single-node/resources.yaml 
b/deploy/platform/kubernetes/feature-cluster/resources.yaml
similarity index 64%
copy from deploy/platform/kubernetes/feature-single-node/resources.yaml
copy to deploy/platform/kubernetes/feature-cluster/resources.yaml
index 5b29142..e710cb7 100644
--- a/deploy/platform/kubernetes/feature-single-node/resources.yaml
+++ b/deploy/platform/kubernetes/feature-cluster/resources.yaml
@@ -73,6 +73,42 @@ spec:
       port: 12800
 
 ---
+apiVersion: batch/v1
+kind: Job
+metadata:
+  name: oap-init-job # @feature: cluster; set up an init job to initialize ES 
templates and indices
+spec:
+  template:
+    metadata:
+      name: oap-init-job
+    spec:
+      serviceAccountName: skywalking-sa-cluster
+      restartPolicy: Never
+      initContainers:
+        - name: wait-for-es
+          image: 
docker.elastic.co/elasticsearch/elasticsearch-oss:${ES_VERSION}
+          command:
+            - 'sh'
+            - '-c'
+            - 'for i in $(seq 1 60); do nc -z -w3 elasticsearch 9200 && exit 0 
|| sleep 5; done; exit 1'
+      containers:
+        - name: oap-init
+          image: ${SW_OAP_IMAGE}
+          env: # @feature: cluster; make sure all env vars are the same with 
the cluster nodes as this will affect templates / indices
+            - name: JAVA_OPTS
+              value: "-Dmode=init" # @feature: cluster; set the OAP mode to 
"init" so the job can complete
+            - name: SW_OTEL_RECEIVER
+              value: default
+            - name: SW_OTEL_RECEIVER_ENABLED_OC_RULES
+              value: vm,oap
+            - name: SW_STORAGE
+              value: elasticsearch
+            - name: SW_STORAGE_ES_CLUSTER_NODES
+              value: elasticsearch:9200
+            - name: SW_TELEMETRY
+              value: prometheus
+
+---
 apiVersion: apps/v1
 kind: Deployment
 metadata:
@@ -80,7 +116,7 @@ metadata:
   labels:
     app: oap
 spec:
-  replicas: 1
+  replicas: 2 # @feature: cluster; set OAP replicas to >1
   selector:
     matchLabels:
       app: oap
@@ -89,6 +125,15 @@ spec:
       labels:
         app: oap
     spec:
+      serviceAccountName: skywalking-sa-cluster # @feature: cluster; set a 
service account with Pod "read" permission
+      initContainers:
+        - name: wait-for-oap-init
+          image: bitnami/kubectl:1.20.12
+          command:
+            - 'kubectl'
+            - 'wait'
+            - '--for=condition=complete'
+            - 'job/oap-init-job'
       containers:
         - name: oap
           image: ${SW_OAP_IMAGE}
@@ -107,6 +152,12 @@ spec:
             - name: http
               containerPort: 12800
           env:
+            - name: JAVA_OPTS
+              value: "-Dmode=no-init"
+            - name: SW_CLUSTER
+              value: kubernetes # @feature: cluster; set cluster coordinator 
to kubernetes
+            - name: SW_CLUSTER_K8S_LABEL
+              value: app=oap # @feature: cluster; set label selectors to 
select OAP Pods as a cluster
             - name: SW_HEALTH_CHECKER
               value: default
             - name: SW_OTEL_RECEIVER
@@ -150,7 +201,7 @@ spec:
       labels:
         app: rocket-bot
     spec:
-      serviceAccountName: skywalking-sa
+      serviceAccountName: skywalking-sa-cluster
       containers:
         - name: rocket-bot
           image: ${SW_ROCKET_BOT_IMAGE}
diff --git a/deploy/platform/kubernetes/feature-single-node/resources.yaml 
b/deploy/platform/kubernetes/feature-single-node/resources.yaml
index 5b29142..3f48173 100644
--- a/deploy/platform/kubernetes/feature-single-node/resources.yaml
+++ b/deploy/platform/kubernetes/feature-single-node/resources.yaml
@@ -150,7 +150,6 @@ spec:
       labels:
         app: rocket-bot
     spec:
-      serviceAccountName: skywalking-sa
       containers:
         - name: rocket-bot
           image: ${SW_ROCKET_BOT_IMAGE}
diff --git a/deploy/platform/kubernetes/feature-so11y/permissions.yaml 
b/deploy/platform/kubernetes/feature-so11y/permissions.yaml
index 0aa91d7..aefc8f7 100644
--- a/deploy/platform/kubernetes/feature-so11y/permissions.yaml
+++ b/deploy/platform/kubernetes/feature-so11y/permissions.yaml
@@ -29,7 +29,7 @@ metadata:
 rules:
   - apiGroups: [ "" ]
     resources:
-      - "pods" # @feature: so11y; OpenTelemetry needs to read OAP pods 
information to get OAP details
+      - "pods" # @feature: so11y; OpenTelemetry needs to read OAP Pods 
information to get OAP details
     verbs: [ "get", "watch", "list" ]
 
 ---

Reply via email to