Skip to content

Building k8s prometheus adapter

aborkar-ibm edited this page Oct 30, 2018 · 9 revisions

Building k8s-prometheus-adapter

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

  • RHEL (7.3, 7.4, 7.5)
  • SLES (12 SP3, 15)
  • Ubuntu (16.04, 18.04)

Prerequisites

  • Docker -- Instructions for install Docker can be found here

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

  • RHEL (7.3, 7.4, 7.5)

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

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

    sudo apt-get update
    sudo apt-get install -y git make golang golang-1.10 tar curl wget mercurial
    sudo rm -v /usr/bin/go
    sudo ln -s /usr/lib/go-1.10/bin/go /usr/bin/go
    
  • 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 (Only for RHEL and SLES) -- 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.2.2
    
  • 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 k8s-prometheus-adapter docker image for s390x

    cd $GOPATH/src/github.com/directxman12/k8s-prometheus-adapter
    make docker-build ARCH=s390x

    Note: make docker-build ARCH=s390x will create directxman12/k8s-prometheus-adapter-s390x:latest which should be tagged directxman12/k8s-prometheus-adapter:0.2.2. The image is tagged 0.2.2 because it fails with a imagePullError issue with tag latest as it always tries to download from the repository instead of checking locally for the image.

  • 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,17 +19,17 @@ spec:
           serviceAccountName: custom-metrics-apiserver
           containers:
           - name: custom-metrics-apiserver
    -        image: directxman12/k8s-prometheus-adapter-amd64
    +        image: directxman12/k8s-prometheus-adapter-s390x:0.2.1
             args:
             - /adapter
             - --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=/default-config.yaml
    +        - --config=/etc/adapter/config.yaml
             ports:
             - containerPort: 6443
             volumeMounts:

    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