opentelemetry-helm-charts icon indicating copy to clipboard operation
opentelemetry-helm-charts copied to clipboard

lifecycleHooks doesn't seem to work

Open navin-rai opened this issue 1 year ago • 3 comments

Hi,

I am deploying opentelemetry-collector in deployment mode and I am using initContainers to use Kuberentes lifecycleHooks, But It seems that binary sleep copied from busybox doesn't seem to work. Below I have pasted values.yaml changes and rendered deployment manifest. Is there anything I am missing or doing wrong.

initContainers:
    - name: test
      image: busybox:latest
      command:
        - cp
      args:
        - /bin/sleep
        - /test/sleep
      volumeMounts:
        - name: test
          mountPath: /test
  
  extraVolumes:
    - name: test
      emptyDir: {}

  extraVolumeMounts:
    - name: test
      mountPath: /test

 lifecycleHooks:
     preStop:
       exec:
         command:
         - /test/sleep
         - "120"

Rendered manifest:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: opentelemetry-collector
  labels:
    helm.sh/chart: opentelemetry-collector-0.48.1
    app.kubernetes.io/name: opentelemetry-collector
    app.kubernetes.io/instance: opentelemetry-collector
    app.kubernetes.io/version: "0.71.0"
    app.kubernetes.io/managed-by: Helm
spec:
  replicas: 1
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      app.kubernetes.io/name: opentelemetry-collector
      app.kubernetes.io/instance: opentelemetry-collector
      component: standalone-collector
  strategy:
    type: RollingUpdate
  template:
    metadata:
      annotations:
        checksum/config: 248445402362f08ffc63fe78849d49f5746a4f8458b5df5b4ea81ed899f13491
        prometheus.io/path: /metrics
        prometheus.io/port: "8888"
        prometheus.io/scrape: "true"
      labels:
        app.kubernetes.io/name: opentelemetry-collector
        app.kubernetes.io/instance: opentelemetry-collector
        component: standalone-collector

    spec:

      serviceAccountName: opentelemetry-collector
      securityContext:
        {}
      containers:
        - name: opentelemetry-collector
          command:
            - /otelcol-contrib
            - --config=/conf/relay.yaml
          securityContext:
            {}
          image: "otel/opentelemetry-collector-contrib:0.71.0
          imagePullPolicy: Always
          ports:
            - name: otlp
              containerPort: 4317
              protocol: TCP
            - name: otlp-http
              containerPort: 4318
              protocol: TCP
          env:
            - name: MY_POD_IP
              valueFrom:
                fieldRef:
                  apiVersion: v1
                  fieldPath: status.podIP
            - name: AWS_ACCESS_KEY_ID
              valueFrom:
                secretKeyRef:
                  key: awsAccessKeyId
                  name: opentelemetry-collector-secret
            - name: AWS_SECRET_ACCESS_KEY
              valueFrom:
                secretKeyRef:
                  key: awsSecretAccessKey
                  name: opentelemetry-collector-secret
          lifecycle:
            preStop:
              exec:
                command:
                - /test/sleep
                - "120"
          livenessProbe:
            httpGet:
              path: /
              port: 13133
          readinessProbe:
            httpGet:
              path: /
              port: 13133
          resources:
            limits:
              cpu: 256m
              memory: 512Mi
          volumeMounts:
            - mountPath: /conf
              name: opentelemetry-collector-configmap
            - mountPath: /test
              name: test
      initContainers:
        - args:
          - /bin/sleep
          - /test/sleep
          command:
          - cp
          image: busybox:latest
          name: test
          volumeMounts:
          - mountPath: /test
            name: test
      volumes:
        - name: opentelemetry-collector-configmap
          configMap:
            name: opentelemetry-collector
            items:
              - key: relay
                path: relay.yaml
        - emptyDir: {}
          name: test
      hostNetwork: false

navin-rai avatar May 14 '23 05:05 navin-rai

If I use postStart lifecycleHooks to copy verify sh or sleep copied to test folder, I can see below errors

errorKubeLifeCycle

navin-rai avatar May 14 '23 05:05 navin-rai

Hi @juissi-t Maybe you can help me on this.

navin-rai avatar May 15 '23 05:05 navin-rai

Maybe someone is still looking for this. This worked for me

  initContainers:
    - name: enable-sleep
      image: alpine
      command: ['/bin/sh', '-c', 'cp /lib/ld-musl-x86_64.so.1 /bin/busybox /app/']
      volumeMounts:
        - name: sleep
          mountPath: /app

  extraVolumes:
    - name: sleep
      emptyDir: {}

  extraVolumeMounts:
    - name: sleep
      mountPath: /lib

  lifecycleHooks:
    preStop:
      exec:
        command: ['/lib/busybox', 'sleep', '15']

veikovx avatar Feb 12 '24 12:02 veikovx