Building k8s prometheus adapter - linux-on-ibm-z/docs GitHub Wiki

Building k8s-prometheus-adapter

The instructions provided below specify the steps to build k8s-prometheus-adapter version 0.5.0 on Linux on IBM Z for the following distributions:

  • RHEL (7.6, 7.7, 7.8, 8.1, 8.2)
  • SLES (12 SP5, 15 SP1)
  • Ubuntu (16.04, 18.04, 20.04)

General Notes:

  • When following the steps below please use a standard permission user unless otherwise specified

  • A directory /<source_root>/ will be referred to in these instructions, this is a temporary writable directory anywhere you'd like to place it

Step 1: Install the Dependencies

 export SOURCE_ROOT=/<source_root>/
  • RHEL (7.6, 7.7, 7.8, 8.1, 8.2)

    sudo yum install -y tar wget gcc git make curl mercurial       
    
  • SLES (12 SP5, 15 SP1)

    sudo zypper install -y tar wget gcc git make curl mercurial python-devel
    
  • Ubuntu (16.04, 18.04, 20.04)

    sudo apt-get update
    sudo apt-get install -y git make gcc tar curl wget mercurial
    
  • Docker packages are provided for SLES, Ubuntu and RHEL (7.5 or higher) in their respective repositories. More information about Docker CE can be found here.

  • Install glide

    wget https://github.com/Masterminds/glide/releases/download/v0.13.1/glide-v0.13.1-linux-s390x.tar.gz
    sudo tar -vxz -f glide-v0.13.1-linux-s390x.tar.gz -C /usr/local/bin --strip=1
    export PATH=$PATH:/usr/local/bin
    
  • Install Go -- Instructions for building Go can be found here.

Step 2: Build and install k8s-prometheus-adapter

  • Setup Environment variable and source folder to build the package
    export GOPATH=$SOURCE_ROOT
    
  • Download k8s-prometheus-adapter source code
    mkdir -p $GOPATH/src/github.com/directxman12
    cd $GOPATH/src/github.com/directxman12
    git clone https://github.com/directxman12/k8s-prometheus-adapter.git
    cd k8s-prometheus-adapter
    git checkout v0.5.0
    
  • Build k8s-prometheus-adapter
    cd $GOPATH/src/github.com/directxman12/k8s-prometheus-adapter
    make all ARCH=s390x    
    

Step 3: Testing and verifying(Optional)

  • Run test cases
    cd $GOPATH/src/github.com/directxman12/k8s-prometheus-adapter
    make test
    make verify
    

Step 4: Deploy k8s-prometheus-adapter to Kubernetes

  • Prerequisites

    • A running Kubernetes cluster.

    • Prometheus -- Instructions to install Prometheus server can be found here.

  • Create namespace custom-metrics to ensure the namespace we choose to install the custom metrics adapter in.

    kubectl create namespace custom-metrics
    
  • Create a secret called cm-adapter-serving-certs with two values: serving.crt and serving.key

    cd $GOPATH/src/github.com/directxman12/k8s-prometheus-adapter
    export PURPOSE=serving
    openssl req -x509 -sha256 -new -nodes -days 365 -newkey rsa:2048 -keyout ${PURPOSE}-ca.key -out ${PURPOSE}-ca.crt -subj "/CN=ca"
    echo '{"signing":{"default":{"expiry":"43800h","usages":["signing","key encipherment","'${PURPOSE}'"]}}}' > "${PURPOSE}-ca-config.json"
    kubectl -n custom-metrics create secret tls cm-adapter-serving-certs --cert=./serving-ca.crt --key=./serving-ca.key
    
  • Make changes to $GOPATH/src/github.com/directxman12/k8s-prometheus-adapter/deploy/manifests/custom-metrics-apiserver-deployment.yaml, to point to your prometheus server and k8s-prometheus-adapter docker image.

    @@ -19,13 +19,13 @@ spec:
           serviceAccountName: custom-metrics-apiserver
           containers:
           - name: custom-metrics-apiserver
    -        image: directxman12/k8s-prometheus-adapter-amd64
    +        image: directxman12/k8s-prometheus-adapter:v0.5.0
             args:
             - --secure-port=6443
    -        - --tls-cert-file=/var/run/serving-cert/serving.crt
    -        - --tls-private-key-file=/var/run/serving-cert/serving.key
    +        - --tls-cert-file=/var/run/serving-cert/tls.crt
    +        - --tls-private-key-file=/var/run/serving-cert/tls.key
             - --logtostderr=true
    -        - --prometheus-url=http://prometheus.prom.svc:9090/
    +        - --prometheus-url=http://localhost:9090/
             - --metrics-relist-interval=1m
             - --v=10
             - --config=/etc/adapter/config.yaml
    

    Notes:
    1. The --tls-private-key-file and --tls-cert-file values are obtained from the values stored in secret cm-adapter-serving-certs. Execute kubectl describe -n custom-metrics secret cm-adapter-serving-certs to view the data.
    2. The --prometheus-url is set to the server and port prometheus server has been started on.

  • Deploy k8s-prometheus-adapter

    cd $GOPATH/src/github.com/directxman12/k8s-prometheus-adapter/deploy
    kubectl create -f manifests/
    

    Note: The custom metrics adapter will launch the custom-metrics-apiserver pod.

References: