You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by ke...@apache.org on 2021/11/05 08:50:32 UTC

[skywalking-showcase] branch main updated: Add Kubernetes deploy target and vm, so11y, highlight target

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


The following commit(s) were added to refs/heads/main by this push:
     new a368bf9  Add Kubernetes deploy target and vm, so11y, highlight target
a368bf9 is described below

commit a368bf9edf773c3f130df49d2b7eb854d7b29e97
Author: kezhenxu94 <ke...@apache.org>
AuthorDate: Fri Nov 5 16:50:10 2021 +0800

    Add Kubernetes deploy target and vm, so11y, highlight target
---
 Makefile.in                                        |  2 +-
 .../platform/docker/docker-compose.so11y.yaml      | 20 +-----
 deploy/platform/kubernetes/Makefile                |  1 -
 .../kubernetes/feature-single-node/resources.yaml  | 27 +++++---
 .../open-telemetry.yaml}                           | 79 ++++++++--------------
 .../kubernetes/feature-so11y/permissions.yaml      | 50 ++++++++------
 .../{resources.yaml => open-telemetry.yaml}        | 57 ++++++++++------
 .../kubernetes/feature-vm/permissions.yaml         | 50 ++++++++------
 scripts/make/help.mk                               | 20 +++++-
 9 files changed, 161 insertions(+), 145 deletions(-)

diff --git a/Makefile.in b/Makefile.in
index 1ce08e0..34df6cc 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -34,4 +34,4 @@ SW_AGENT_NODEJS_FRONTEND_VERSION ?= af0565a67d382b683c1dbd94c379b7080db61449
 # ALL variables should be listed above ^^
 EXPORTED_VARS := $(filter-out <%,$(.VARIABLES))
 
-features ?= all
+features ?= single-node,agent,so11y,vm
diff --git a/Makefile.in b/deploy/platform/docker/docker-compose.so11y.yaml
similarity index 57%
copy from Makefile.in
copy to deploy/platform/docker/docker-compose.so11y.yaml
index 1ce08e0..1f069f1 100644
--- a/Makefile.in
+++ b/deploy/platform/docker/docker-compose.so11y.yaml
@@ -16,22 +16,4 @@
 # under the License.
 #
 
-comma := ,
-
-.EXPORT_ALL_VARIABLES:
-
-HUB ?= ghcr.io/apache/skywalking-showcase
-TAG ?= $(shell git rev-parse --short HEAD)
-
-ES_VERSION ?= 7.10.0
-
-SW_OAP_IMAGE ?= ghcr.io/apache/skywalking/oap:c9bd79e8bb974e404766e3490c00c7404b9baf1e
-SW_ROCKET_BOT_IMAGE ?= ghcr.io/apache/skywalking/ui:c9bd79e8bb974e404766e3490c00c7404b9baf1e
-
-SW_AGENT_NODEJS_BACKEND_VERSION ?= e755659c7f308d3b5589619778c8360308cb14f8
-SW_AGENT_NODEJS_FRONTEND_VERSION ?= af0565a67d382b683c1dbd94c379b7080db61449
-
-# ALL variables should be listed above ^^
-EXPORTED_VARS := $(filter-out <%,$(.VARIABLES))
-
-features ?= all
+# So11y in Docker compose is enabled by default
diff --git a/deploy/platform/kubernetes/Makefile b/deploy/platform/kubernetes/Makefile
index 2e161b6..ff1a9b7 100644
--- a/deploy/platform/kubernetes/Makefile
+++ b/deploy/platform/kubernetes/Makefile
@@ -26,7 +26,6 @@ else
 endif
 
 resources := $(foreach dir,$(features),$(wildcard $(dir)/*))
-resources := $(resources) resources.yaml # Basic resources are always applied
 
 resources_deploy := $(foreach r,$(resources),$(r).deploy)
 .PHONY: $(resources_deploy)
diff --git a/deploy/platform/kubernetes/feature-single-node/resources.yaml b/deploy/platform/kubernetes/feature-single-node/resources.yaml
index 29d3583..5b29142 100644
--- a/deploy/platform/kubernetes/feature-single-node/resources.yaml
+++ b/deploy/platform/kubernetes/feature-single-node/resources.yaml
@@ -65,14 +65,12 @@ spec:
   selector:
     app: oap
   ports:
+    - name: metrics
+      port: 1234
     - name: grpc
-      protocol: TCP
       port: 11800
-      targetPort: 11800
     - name: http
-      protocol: TCP
       port: 12800
-      targetPort: 12800
 
 ---
 apiVersion: apps/v1
@@ -96,25 +94,31 @@ spec:
           image: ${SW_OAP_IMAGE}
           resources:
             limits:
-              cpu: 2000m
-              memory: "2048Mi"
+              cpu: 4000m
+              memory: "4096Mi"
             requests:
               cpu: 1000m
               memory: "1024Mi"
           ports:
-            - containerPort: 11800
-            - containerPort: 12800
+            - name: metrics # @feature: so11y; set a name for the metrics port that can be referenced in otel config
+              containerPort: 1234
+            - name: grpc
+              containerPort: 11800
+            - name: http
+              containerPort: 12800
           env:
             - name: SW_HEALTH_CHECKER
               value: default
             - name: SW_OTEL_RECEIVER
-              value: default
+              value: default # @feature: so11y; enable OpenTelemetry receiver to receive OAP metrics
             - name: SW_OTEL_RECEIVER_ENABLED_OC_RULES
-              value: vm
+              value: vm,oap # @feature: so11y; enable oap rules to analyze OAP metrics
             - name: SW_STORAGE
               value: elasticsearch
             - name: SW_STORAGE_ES_CLUSTER_NODES
               value: elasticsearch:9200
+            - name: SW_TELEMETRY
+              value: prometheus # @feature: so11y; expose the metrics of self o11y through prometheus
 
 ---
 apiVersion: v1
@@ -146,6 +150,7 @@ spec:
       labels:
         app: rocket-bot
     spec:
+      serviceAccountName: skywalking-sa
       containers:
         - name: rocket-bot
           image: ${SW_ROCKET_BOT_IMAGE}
@@ -153,4 +158,4 @@ spec:
             - containerPort: 8080
           env:
             - name: SW_OAP_ADDRESS
-              value: oap:12800
+              value: http://oap:12800
diff --git a/deploy/platform/kubernetes/feature-vm/resources.yaml b/deploy/platform/kubernetes/feature-so11y/open-telemetry.yaml
similarity index 60%
copy from deploy/platform/kubernetes/feature-vm/resources.yaml
copy to deploy/platform/kubernetes/feature-so11y/open-telemetry.yaml
index 1cf6bae..becafaf 100644
--- a/deploy/platform/kubernetes/feature-vm/resources.yaml
+++ b/deploy/platform/kubernetes/feature-so11y/open-telemetry.yaml
@@ -15,62 +15,37 @@
 # specific language governing permissions and limitations
 # under the License.
 #
----
-apiVersion: v1
-kind: Service
-metadata:
-  name: vm
-spec:
-  selector:
-    app: vm
-  ports:
-    - protocol: TCP
-      port: 9100
-      targetPort: 9100
 
----
-apiVersion: apps/v1
-kind: Deployment
-metadata:
-  name: vm-deployment
-  labels:
-    app: vm
-spec:
-  replicas: 2
-  selector:
-    matchLabels:
-      app: vm
-  template:
-    metadata:
-      labels:
-        app: vm
-    spec:
-      containers:
-        - name: vm
-          image: quay.io/prometheus/node-exporter:v1.2.2
-          ports:
-            - containerPort: 9100
+# @feature: so11y; in Kubernetes, it's better to set service discovery so the OAP instances are not always "localhost:1234"
+
 ---
 apiVersion: v1
 kind: ConfigMap
 metadata:
-  name: otel-collector-conf
+  name: otel-collector-conf-so11y
   labels:
-    app: opentelemetry
-    component: otel-collector-conf
+    app: opentelemetry-so11y
 data:
   otel-collector-config: |
     receivers:
       prometheus:
         config:
           scrape_configs:
-            - job_name: 'otel-collector'
-              scrape_interval: 10s
-              static_configs:
-                - targets: [ 'vm:9100' ]
-
-    processors:
-      batch:
+            - job_name: 'skywalking-so11y'
+              metrics_path: '/metrics'
+              kubernetes_sd_configs:
+                - role: pod
+              relabel_configs:
+                - source_labels: [__meta_kubernetes_pod_container_name, __meta_kubernetes_pod_container_port_name]
+                  action: keep
+                  regex: oap;metrics # @feature: so11y; reference the name of the metrics port
+                - source_labels: []
+                  target_label: service
+                  replacement: oap-server
+                - source_labels: [__meta_kubernetes_pod_name]
+                  target_label: host_name
+                  regex: (.+)
+                  replacement: $$1
 
     exporters:
       opencensus:
@@ -83,26 +58,26 @@ data:
       pipelines:
         metrics:
           receivers: [ prometheus ]
-          processors: [ batch ]
           exporters: [ opencensus,logging ]
 
 ---
 apiVersion: apps/v1
 kind: Deployment
 metadata:
-  name: otel-deployment
+  name: otel-deployment-so11y
   labels:
-    app: otel
+    app: otel-so11y
 spec:
   replicas: 1
   selector:
     matchLabels:
-      app: otel
+      app: otel-so11y
   template:
     metadata:
       labels:
-        app: otel
+        app: otel-so11y
     spec:
+      serviceAccountName: otel-sa-so11y
       containers:
         - name: otel
           image: otel/opentelemetry-collector:0.29.0
@@ -110,12 +85,12 @@ spec:
             - "/otelcol"
             - "--config=/conf/otel-collector-config.yaml"
           volumeMounts:
-            - name: otel-collector-config-vol
+            - name: otel-collector-config-vol-so11y
               mountPath: /conf
       volumes:
-        - name: otel-collector-config-vol
+        - name: otel-collector-config-vol-so11y
           configMap:
-            name: otel-collector-conf
+            name: otel-collector-conf-so11y
             items:
               - key: otel-collector-config
                 path: otel-collector-config.yaml
diff --git a/Makefile.in b/deploy/platform/kubernetes/feature-so11y/permissions.yaml
similarity index 55%
copy from Makefile.in
copy to deploy/platform/kubernetes/feature-so11y/permissions.yaml
index 1ce08e0..0aa91d7 100644
--- a/Makefile.in
+++ b/deploy/platform/kubernetes/feature-so11y/permissions.yaml
@@ -15,23 +15,33 @@
 # specific language governing permissions and limitations
 # under the License.
 #
-
-comma := ,
-
-.EXPORT_ALL_VARIABLES:
-
-HUB ?= ghcr.io/apache/skywalking-showcase
-TAG ?= $(shell git rev-parse --short HEAD)
-
-ES_VERSION ?= 7.10.0
-
-SW_OAP_IMAGE ?= ghcr.io/apache/skywalking/oap:c9bd79e8bb974e404766e3490c00c7404b9baf1e
-SW_ROCKET_BOT_IMAGE ?= ghcr.io/apache/skywalking/ui:c9bd79e8bb974e404766e3490c00c7404b9baf1e
-
-SW_AGENT_NODEJS_BACKEND_VERSION ?= e755659c7f308d3b5589619778c8360308cb14f8
-SW_AGENT_NODEJS_FRONTEND_VERSION ?= af0565a67d382b683c1dbd94c379b7080db61449
-
-# ALL variables should be listed above ^^
-EXPORTED_VARS := $(filter-out <%,$(.VARIABLES))
-
-features ?= all
+---
+apiVersion: v1
+kind: ServiceAccount
+metadata:
+  name: otel-sa-so11y
+
+---
+kind: ClusterRole
+apiVersion: rbac.authorization.k8s.io/v1
+metadata:
+  name: otel-role-so11y
+rules:
+  - apiGroups: [ "" ]
+    resources:
+      - "pods" # @feature: so11y; OpenTelemetry needs to read OAP pods information to get OAP details
+    verbs: [ "get", "watch", "list" ]
+
+---
+apiVersion: rbac.authorization.k8s.io/v1
+kind: ClusterRoleBinding
+metadata:
+  name: otel-role-binding-so11y
+roleRef:
+  apiGroup: rbac.authorization.k8s.io
+  kind: ClusterRole
+  name: otel-role-so11y
+subjects:
+  - kind: ServiceAccount
+    name: otel-sa-so11y
+    namespace: default
diff --git a/deploy/platform/kubernetes/feature-vm/resources.yaml b/deploy/platform/kubernetes/feature-vm/open-telemetry.yaml
similarity index 61%
rename from deploy/platform/kubernetes/feature-vm/resources.yaml
rename to deploy/platform/kubernetes/feature-vm/open-telemetry.yaml
index 1cf6bae..0f84580 100644
--- a/deploy/platform/kubernetes/feature-vm/resources.yaml
+++ b/deploy/platform/kubernetes/feature-vm/open-telemetry.yaml
@@ -15,6 +15,9 @@
 # specific language governing permissions and limitations
 # under the License.
 #
+
+# @feature: pretend these Pods are virtual machines
+
 ---
 apiVersion: v1
 kind: Service
@@ -26,7 +29,6 @@ spec:
   ports:
     - protocol: TCP
       port: 9100
-      targetPort: 9100
 
 ---
 apiVersion: apps/v1
@@ -48,29 +50,44 @@ spec:
       containers:
         - name: vm
           image: quay.io/prometheus/node-exporter:v1.2.2
+          resources:
+            limits:
+              cpu: 100m
+              memory: "128Mi"
           ports:
             - containerPort: 9100
+              name: metrics
+
+# @feature: vm; set OpenTelemetry config to scrape the VM metrics
 ---
 apiVersion: v1
 kind: ConfigMap
 metadata:
-  name: otel-collector-conf
+  name: otel-collector-conf-vm
   labels:
-    app: opentelemetry
-    component: otel-collector-conf
+    app: otel-vm
 data:
   otel-collector-config: |
     receivers:
       prometheus:
         config:
           scrape_configs:
-            - job_name: 'otel-collector'
-              scrape_interval: 10s
-              static_configs:
-                - targets: [ 'vm:9100' ]
-
-    processors:
-      batch:
+            # @feature: vm; this is only for demo, in real scenarios the VM addresses should be static, not via service discovery
+            - job_name: 'vm-monitoring'
+              metrics_path: '/metrics'
+              kubernetes_sd_configs:
+                - role: pod
+              relabel_configs:
+                - source_labels: [__meta_kubernetes_pod_container_name, __meta_kubernetes_pod_container_port_name]
+                  action: keep
+                  regex: vm;metrics # @feature: vm; reference the name of the metrics port
+                - source_labels: []
+                  target_label: service
+                  replacement: vm
+                - source_labels: [__meta_kubernetes_pod_name]
+                  target_label: host_name
+                  regex: (.+)
+                  replacement: $$1
 
     exporters:
       opencensus:
@@ -83,39 +100,39 @@ data:
       pipelines:
         metrics:
           receivers: [ prometheus ]
-          processors: [ batch ]
           exporters: [ opencensus,logging ]
 
 ---
 apiVersion: apps/v1
 kind: Deployment
 metadata:
-  name: otel-deployment
+  name: otel-deployment-vm
   labels:
-    app: otel
+    app: otel-vm
 spec:
   replicas: 1
   selector:
     matchLabels:
-      app: otel
+      app: otel-vm
   template:
     metadata:
       labels:
-        app: otel
+        app: otel-vm
     spec:
+      serviceAccountName: otel-sa-vm
       containers:
-        - name: otel
+        - name: otel-vm
           image: otel/opentelemetry-collector:0.29.0
           command:
             - "/otelcol"
             - "--config=/conf/otel-collector-config.yaml"
           volumeMounts:
-            - name: otel-collector-config-vol
+            - name: otel-collector-config-vol-vm
               mountPath: /conf
       volumes:
-        - name: otel-collector-config-vol
+        - name: otel-collector-config-vol-vm
           configMap:
-            name: otel-collector-conf
+            name: otel-collector-conf-vm
             items:
               - key: otel-collector-config
                 path: otel-collector-config.yaml
diff --git a/Makefile.in b/deploy/platform/kubernetes/feature-vm/permissions.yaml
similarity index 57%
copy from Makefile.in
copy to deploy/platform/kubernetes/feature-vm/permissions.yaml
index 1ce08e0..3644f9c 100644
--- a/Makefile.in
+++ b/deploy/platform/kubernetes/feature-vm/permissions.yaml
@@ -15,23 +15,33 @@
 # specific language governing permissions and limitations
 # under the License.
 #
-
-comma := ,
-
-.EXPORT_ALL_VARIABLES:
-
-HUB ?= ghcr.io/apache/skywalking-showcase
-TAG ?= $(shell git rev-parse --short HEAD)
-
-ES_VERSION ?= 7.10.0
-
-SW_OAP_IMAGE ?= ghcr.io/apache/skywalking/oap:c9bd79e8bb974e404766e3490c00c7404b9baf1e
-SW_ROCKET_BOT_IMAGE ?= ghcr.io/apache/skywalking/ui:c9bd79e8bb974e404766e3490c00c7404b9baf1e
-
-SW_AGENT_NODEJS_BACKEND_VERSION ?= e755659c7f308d3b5589619778c8360308cb14f8
-SW_AGENT_NODEJS_FRONTEND_VERSION ?= af0565a67d382b683c1dbd94c379b7080db61449
-
-# ALL variables should be listed above ^^
-EXPORTED_VARS := $(filter-out <%,$(.VARIABLES))
-
-features ?= all
+---
+apiVersion: v1
+kind: ServiceAccount
+metadata:
+  name: otel-sa-vm
+
+---
+kind: ClusterRole
+apiVersion: rbac.authorization.k8s.io/v1
+metadata:
+  name: otel-role-vm
+rules:
+  - apiGroups: [ "" ]
+    resources:
+      - "pods"
+    verbs: [ "get", "watch", "list" ]
+
+---
+apiVersion: rbac.authorization.k8s.io/v1
+kind: ClusterRoleBinding
+metadata:
+  name: otel-role-binding-vm
+roleRef:
+  apiGroup: rbac.authorization.k8s.io
+  kind: ClusterRole
+  name: otel-role-vm
+subjects:
+  - kind: ServiceAccount
+    name: otel-sa-vm
+    namespace: default
diff --git a/scripts/make/help.mk b/scripts/make/help.mk
index 0ca065d..5d4f0e4 100644
--- a/scripts/make/help.mk
+++ b/scripts/make/help.mk
@@ -1,3 +1,21 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
 ##@ Other targets
 
 define usage
@@ -27,7 +45,7 @@ features := $(subst $(comma), ,$(FEATURE_FLAGS))
 features := $(foreach f,$(features),@feature: *$(f)*)
 
 .PHONY: highlight
-highlight:  ## Highlight the important points of a feature
+highlight:  ## Highlight the important contents of a feature
 	@if [ "$(FEATURE_FLAGS)" = "" ]; then \
 	  echo 'FEATURE_FLAGS must be set in highlight target'; \
   	  exit 1; \