Skip to content

Latest commit

 

History

History
206 lines (153 loc) · 6.99 KB

BUILD.md

File metadata and controls

206 lines (153 loc) · 6.99 KB

Build & Deploy KEDA

Table of Contents generated with DocToc

Building

This helps you pull and build quickly - dev containers launch the project inside a container with all the tooling required for a consistent and seamless developer experience.

This means you don't have to install and configure your dev environment as the container handles this for you.

To get started install VSCode and the Remote Containers extensions

Clone the repo and launch code:

git clone git@github.com:kedacore/keda.git
cd keda
code .

Once VSCode launches run CTRL+SHIFT+P -> Remote-Containers: Reopen in container and then use the integrated terminal to run:

make build

Note: The first time you run the container it will take some time to build and install the tooling. The image will be cached so this is only required the first time.

Locally directly

This project is using Operator SDK framework, make sure you have installed the right version. To check the current version used for KEDA check the RELEASE_VERSION in file tools/build-tools.Dockerfile.

git clone git@github.com:kedacore/keda.git
cd keda
make build

If the build process fails due to some "checksum mismatch" errors, make sure that GOPROXY and GOSUMDB environment variables are set properly. With Go installation on Fedora, for example, it could happen they are wrong.

go env GOPROXY GOSUMDB
direct
off

If not set properly you can just run.

go env -w GOPROXY=https://proxy.golang.org,direct GOSUMDB=sum.golang.org

Deploying

Custom KEDA locally outside cluster

The Operator SDK framework allows you to run the operator/controller locally outside the cluster without a need of building an image. This should help during development/debugging of KEDA Operator or Scalers.

Note: This approach works only on Linux or macOS.

To have fully operational KEDA we need to deploy Metrics Server first.

  1. Deploy CRDs and KEDA into keda namespace
    make deploy
  2. Scale down keda-operator Deployment
    kubectl scale deployment/keda-operator --replicas=0 -n keda
  3. Run the operator locally with the default Kubernetes config file present at $HOME/.kube/config and change the operator log level via --zap-log-level= if needed
    make run ARGS="--zap-log-level=debug"

Custom KEDA as an image

If you want to change KEDA's behaviour, or if you have created a new scaler (more docs on this to come) and you want to deploy it as part of KEDA. Do the following:

  1. Make your change in the code.
  2. Build and publish images with your changes, IMAGE_REPO should point to your repository, IMAGE_REGISTRY allows you to use registry of your choice eg. quay.io, default is ghcr.io
    IMAGE_REGISTRY=docker.io IMAGE_REPO=johndoe make publish
  3. Deploy KEDA with your custom images.
    IMAGE_REGISTRY=docker.io IMAGE_REPO=johndoe make deploy
  4. Once the KEDA pods are up, check the logs to verify everything running ok, eg:
    kubectl logs -l app=keda-operator -n keda -f
    kubectl logs -l app=keda-metrics-apiserver -n keda -f

Debugging

Using VS Code

Follow these instructions if you want to debug the KEDA operator using VS Code.

  1. Create a launch.json file inside the .vscode/ folder in the repo with the following configuration:
    {
     "configurations": [
          {
             "name": "Launch file",
             "type": "go",
             "request": "launch",
             "mode": "debug",
             "program": "${workspaceFolder}/main.go",
             "env": {"WATCH_NAMESPACE": ""}
         }
     ]
    }
    Refer to this for more information about debugging with VS Code.
  2. Deploy CRDs and KEDA into keda namespace
    make deploy
  3. Scale down keda-operator Deployment
    kubectl scale deployment/keda-operator --replicas=0 -n keda
  4. Set breakpoints in the code as required.
  5. Select Run > Start Debugging or press F5 to start debugging.

Miscellaneous

Setting log levels

You can change default log levels for both KEDA Operator and Metrics Server. KEDA Operator uses Operator SDK logging mechanism.

KEDA Operator logging

To change the logging level, find --zap-log-level= argument in Operator Deployment section in config/manager/manager.yaml file, modify its value and redeploy.

Allowed values are debug, info, error, or an integer value greater than 0, specified as string

Default value: info

To change the logging format, find --zap-encoder= argument in Operator Deployment section in config/manager/manager.yaml file, modify its value and redeploy.

Allowed values are json and console

Default value: console

To change the logging time encoding, find --zap-time-encoding= argument in Operator Deployment section in config/manager/manager.yaml file, modify its value and redeploy.

Allowed values are epoch, millis, nano, iso8601, rfc3339 or rfc3339nano

Default value: rfc3339

Note: Example of some of the logging time encoding values and the output:

epoch - 1.6533943565181081e+09
iso8601 - 2022-05-24T12:10:19.411Z
rfc3339 - 2022-05-24T12:07:40Z
rfc3339nano - 2022-05-24T12:10:19.411Z

Metrics Server logging

Find --v=0 argument in Operator Deployment section in config/metrics-server/deployment.yaml file, modify its value and redeploy.

Allowed values are "0" for info, "4" for debug, or an integer value greater than 0, specified as string

Default value: "0"

CPU/Memory Profiling

Refer to Enabling Memory Profiling on KEDA v2.