Skip to content

Building k8s prometheus adapter

aborkar-ibm edited this page Jun 3, 2019 · 9 revisions

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.4, 7.5, 7.6)
  • SLES (12 SP4, 15)
  • Ubuntu (16.04, 18.04, 19.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.4, 7.5, 7.6)

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

    sudo zypper install -y tar wget gcc git make curl mercurial python-devel
    
  • Ubuntu (16.04, 18.04, 19.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. Instructions for installing Docker on RHEL(7.3) can be found here. You may use the same instructions for RHEL (7.4) as the binaries are expected to be compatible. 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:

Clone this wiki locally