From 04919e47f279fb28ec1ae39485df45f953501d09 Mon Sep 17 00:00:00 2001 From: ChrsMark Date: Fri, 12 Apr 2024 13:02:20 +0300 Subject: [PATCH 1/2] Add k8s makefile targets Signed-off-by: ChrsMark --- Makefile | 19 ++++++ .../kubernetes/daemonset-collector-dev.yaml | 61 +++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 examples/kubernetes/daemonset-collector-dev.yaml diff --git a/Makefile b/Makefile index 3e735d47da54..f4befbba4b8f 100644 --- a/Makefile +++ b/Makefile @@ -396,6 +396,25 @@ checkmetadata: $(CHECKFILE) checkapi: $(GOCMD) run cmd/checkapi/main.go . +.PHONY: kind-ready +kind-ready: + @if [ -n "$(shell kind get clusters -q)" ]; then echo "kind is ready"; else echo "kind not ready"; exit 1; fi + +.PHONY: kind-build +kind-build: kind-ready docker-otelcontribcol + docker tag otelcontribcol otelcontribcol-dev:0.0.1 + kind load docker-image otelcontribcol-dev:0.0.1 + +.PHONY: kind-install-daemonset +kind-install-daemonset: kind-ready kind-uninstall-daemonset## Install a local Collector version into the cluster. + @echo "Installing Collector" + helm install daemonset-collector-dev open-telemetry/opentelemetry-collector --values ./examples/kubernetes/daemonset-collector-dev.yaml + +.PHONY: kind-uninstall-daemonset +kind-uninstall-daemonset: kind-ready + @echo "Uninstalling Collector" + helm uninstall --ignore-not-found daemonset-collector-dev + .PHONY: all-checklinks all-checklinks: $(MAKE) $(FOR_GROUP_TARGET) TARGET="checklinks" diff --git a/examples/kubernetes/daemonset-collector-dev.yaml b/examples/kubernetes/daemonset-collector-dev.yaml new file mode 100644 index 000000000000..4169f1e15296 --- /dev/null +++ b/examples/kubernetes/daemonset-collector-dev.yaml @@ -0,0 +1,61 @@ +mode: daemonset + +image: + repository: otelcontribcol-dev + tag: "0.0.1" + pullPolicy: IfNotPresent + +command: + name: otelcontribcol + +extraEnvs: + - name: K8S_NODE_NAME + valueFrom: + fieldRef: + fieldPath: spec.nodeName + +clusterRole: + create: true + rules: + - apiGroups: + - '' + resources: + - 'pods' + - 'nodes' + verbs: + - 'get' + - 'list' + - 'watch' + - apiGroups: [ "" ] + resources: [ "nodes/stats", "nodes/proxy"] + verbs: [ "get" ] + + +config: + exporters: + debug: + verbosity: detailed + receivers: + kubeletstats: + collection_interval: 10s + auth_type: 'serviceAccount' + endpoint: '${env:K8S_NODE_NAME}:10250' + insecure_skip_verify: true + k8s_api_config: + auth_type: serviceAccount + metrics: + container.cpu.utilization: + enabled: true + container.cpu.time: + enabled: true + container.cpu.usage: + enabled: true + k8s.container.cpu_limit_utilization: + enabled: true + + service: + pipelines: + metrics: + receivers: [kubeletstats] + processors: [batch] + exporters: [debug] \ No newline at end of file From cbefd212a1881f24c28225d247cba1bf28bdf72f Mon Sep 17 00:00:00 2001 From: ChrsMark Date: Wed, 15 May 2024 12:29:42 +0300 Subject: [PATCH 2/2] add dev docs part Signed-off-by: ChrsMark --- examples/kubernetes/dev-docs.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 examples/kubernetes/dev-docs.md diff --git a/examples/kubernetes/dev-docs.md b/examples/kubernetes/dev-docs.md new file mode 100644 index 000000000000..b42e59c1e1ab --- /dev/null +++ b/examples/kubernetes/dev-docs.md @@ -0,0 +1,21 @@ +# Running OpenTelemetry Collector from source on k8s + +Developing Collector's features that target to run on a Kubernetes environment require some special handling +for building and running the patches locally. + + +In order to build the Collector from source and deploy it on a local kind cluster +(a kind cluster is required to be installed already) use the following Makefile targets: + +#### Build the Collector +`make kind-build` + +#### Install the Collector as Daemonset +`make kind-install-daemonset` + +This command will install the Collector using the [`daemonset-collector-dev.yaml`](./daemonset-collector-dev.yaml) +configuration sample. +This only stands as a sample configuration and users need to tune this according to their needs. + +#### Uninstall the Daemonset +`make kind-uninstall-daemonset`