kuberneteshttp-headersauthorizationgoogle-kubernetes-enginevictoriametrics

how to scrape metrics with bearer token auth?


vmagent version: 1.79

i use k8s in GCP

So i create kind - secret, which have a key "bearer" with some secret-key "XXX"

In another kind i want to use this secret-key as base auth token to scrape metrics from host1, host2

i receive an error 404, but if i use curl with header - all ok

---
apiVersion: v1
kind: Secret
metadata:
  name: web-site-token
data:
  bearer: XXX
type: Opaque
---
apiVersion: operator.victoriametrics.com/v1beta1
kind: VMStaticScrape
metadata:
  name: web-site
  labels:
    xxx.com/vmagent: nodes
spec:
  jobName: web-site
  targetEndpoints:
    - targets:
        - host1:9254
        - host2:9254
      path: /internal/metrics
      labels:
        env: preupdate
        region: us
        domain: web
        site: game
      scheme: http
      authorization:
        credentials:
          key: bearer
          name: web-site-token
      tlsConfig:
        insecureSkipVerify: true

Solution

  • Here is the answer

    First kind - secret, where i can store token

    ---
    apiVersion: v1
    kind: Secret
    metadata:
      name: web-site-token
    data:
      bearer: xxx
    type: Opaque
    ---
    apiVersion: operator.victoriametrics.com/v1beta1
    kind: VMStaticScrape
    metadata:
      name: web-site
      labels:
        xxx.com/vmagent: nodes
    spec:
      jobName: site
      targetEndpoints:
        - targets:
            - xxx.com:9254
          path: /internal/metrics
          labels:
            env: preprod
            region: eu
            domain: web
            site: xxx
          scheme: http
          authorization:
            credentials:
              key: bearer
              name: web-site-token
            type: ' '