From 54b25f76b0c1c129f95da58f48e64a00b19d6c6e Mon Sep 17 00:00:00 2001 From: Chris Mark Date: Wed, 22 May 2024 14:34:23 +0300 Subject: [PATCH] Add k8s makefile targets (#32349) **Description:** First attempt for https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/32348. **Link to tracking Issue:** https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/32348 **Testing:** **Documentation:** --------- Signed-off-by: ChrsMark --- Makefile | 19 ++++++ .../kubernetes/daemonset-collector-dev.yaml | 61 +++++++++++++++++++ examples/kubernetes/dev-docs.md | 21 +++++++ 3 files changed, 101 insertions(+) create mode 100644 examples/kubernetes/daemonset-collector-dev.yaml create mode 100644 examples/kubernetes/dev-docs.md 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 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`