How to install curl in alertmanager pod in kubernetes

Viewed 1041

I want to use curl in alertmanger pod like this:

curl www.google.com

It shows ash: curl: not found, so I want to install curl:

/alertmanager # apk add curl
ash: apk: not found
/alertmanager # yum install curl
ash: yum: not found
/alertmanager # apt install curl
ash: apt: not found
/alertmanager # apt-get install curl
ash: apt-get: not found

So what should I do to install curl in this pod? this is my yaml:

kind: Deployment
apiVersion: apps/v1
metadata:
  name: alertmanager
  namespace: kube-system
  labels:
    addonmanager.kubernetes.io/mode: Reconcile
    k8s-app: alertmanager
    kubernetes.io/cluster-service: 'true'
    version: v0.14.0
  annotations:
    deployment.kubernetes.io/revision: '1'
spec:
  replicas: 1
  selector:
    matchLabels:
      k8s-app: alertmanager
      version: v0.14.0
  template:
    metadata:
      creationTimestamp: null
      labels:
        k8s-app: alertmanager
        version: v0.14.0
      annotations:
        scheduler.alpha.kubernetes.io/critical-pod: ''
    spec:
      volumes:
        - name: config-volume
          configMap:
            name: alertmanager-config
            defaultMode: 420
        - name: storage-volume
          persistentVolumeClaim:
            claimName: alertmanager
      containers:
        - name: prometheus-alertmanager
          image: 'prom/alertmanager:v0.14.0'
          args:
            - '--config.file=/etc/config/alertmanager.yml'
            - '--storage.path=/data'
            - '--web.external-url=/'
          ports:
            - containerPort: 9093
              protocol: TCP
          resources:
            limits:
              cpu: 10m
              memory: 50Mi
            requests:
              cpu: 10m
              memory: 50Mi
          volumeMounts:
            - name: config-volume
              mountPath: /etc/config
            - name: storage-volume
              mountPath: /data
          readinessProbe:
            httpGet:
              path: '/#/status'
              port: 9093
              scheme: HTTP
            initialDelaySeconds: 30
            timeoutSeconds: 30
            periodSeconds: 10
            successThreshold: 1
            failureThreshold: 3
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
          imagePullPolicy: IfNotPresent
        - name: prometheus-alertmanager-configmap-reload
          image: 'jimmidyson/configmap-reload:v0.1'
          args:
            - '--volume-dir=/etc/config'
            - '--webhook-url=http://localhost:9093/-/reload'
          resources:
            limits:
              cpu: 10m
              memory: 10Mi
            requests:
              cpu: 10m
              memory: 10Mi
          volumeMounts:
            - name: config-volume
              readOnly: true
              mountPath: /etc/config
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
          imagePullPolicy: IfNotPresent
      restartPolicy: Always
      terminationGracePeriodSeconds: 30
      dnsPolicy: ClusterFirst
      securityContext: {}
      schedulerName: default-scheduler
      priorityClassName: system-cluster-critical
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 25%
      maxSurge: 25%
  revisionHistoryLimit: 10
  progressDeadlineSeconds: 600
1 Answers

Looking at the Dockerfile of alert manager it uses busybox which does not come with any package manager installed. You have two options

  1. If possible use wget instead of curl
  2. Modify the Dockerfile of alert manager to use alpine instead of busybox and build your own docker image from that modified Dockerfile. alpine comes with apk package manager which can be used to install curl via apk add curl command.
Related