22-02-2020

Using Knative with Otomi Stack

Kubernetes is complex and needs a lot of configuration to run properly. To be able to deploy containerized applications to Kubernetes, developers have to create configuration files, manage logging and tracing, and write their own CI/CD scripts using tools like Jenkins or Drone.

Knative helps developers by hiding many of these tasks, simplifying container-based management and enabling you to concentrate on writing application code. Otomi Stack supports Knative out-of-the-box together with all Istio service mesh features. When Otomi Stack is installed on Kubernetes version 1.15.x clusters, you can directly start using Knative. This makes deploying and managing cloud native applications really easy. Otomi Stack delivers an extra abstraction layer on top of Knative, so you don’t even have to know how to use Knative. Just tell Otomi Stack which container image to run and if you would like to scale to zero or not.

In this post we’ll explain 2 current supported ways to deploy containers with Otomi Stack and Knative. We’ll also take a look at a new feature that will be available in the upcoming new release of Otomi Stack: deploying containers with Knative and automated CD.

Option 1: Deploy with Knative using Otomi Stack values

All Otomi Stack features are configured using a simple set of values. In a previous post we explained how to simply configure ingress for services (also for Knative services).

To deploy your container using Knative, go to the cloud/cluster/team values and add the following service:

teamConfig:
  teams:
    team1:
      name: team1
      services:
        - name: hello
          ksvc:
            image:
              repository: otomi/helloworld-nodejs
              tag: 1.1.3

The name of the service will be used for short URLs when the service is configured with a public URL. When the values are committed, Otomi Stack will automatically configure and deploy the Knative service.

Scale-to-zero or not

Knative offers the ability to scale-to-zero. This means a container can be reduced down to zero replicas when idle and brought back to the required amount of replicas when it is needed. By default Otomi Stack configures Knative to scale-to-zero. To disable the scale-to-zero feature, add the following annotation to the service:

teamConfig:
  teams:
    team1:
      name: team1
      services:
        - name: hello
          ksvc:
            image:
              repository: otomi/helloworld-nodejs
              tag: 1.1.3
            annotations:
              # Disable scale to zero with a minScale of 1.
              autoscaling.knative.dev/minScale: '1'

Option 2: Deploying a Knative service yourself

When a team is added to a Cloud or cluster, the team will be provided with a bearer token of the team service account. With this token a team can deploy allowed objects to their team namespace. Because Otomi Stack provides Knative out-of-the-box, teams can also deploy Knative services themselves. Here’s an example of a simple Knative service manifest file:

apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: hello
  namespace: team-team1
spec:
  template:
    spec:
      containers:
        - image: otomi/helloworld-nodejs:1.1.3
          env:
            - name: VERSION
              value: "1.1.3"

Comming soon: Deploying with Knative and automated CD

The next release of Otomi Stack will also support automated CD together with Knative. The the following values example shows how automated CD can be added to a service:

teamConfig:
  teams:
    team1:
      name: team1
      services:
        - name: hello
          ksvc:
            autoCD:
              tagMatcher: semver 
              semver: ~1.1
            image:
              repository: otomi/helloworld-nodejs
              tag: 1.1.3

The tagMatcher can be semver, glob or regexp. Flux will sort images based on the selected image filter pattern type. In the example we use semver tagging. When a new image is pushed, the new image will be automatically deployed. Read more about Flux and tagging pattern types here.

Summary

In this blog post we have showed 2 options for deploying containers with Knative to a Otomi Stack controlled Kubernetes cluster:

  • Using Otomi Stack values to use Knative with automated CD
  • Deploy Knative services yourself

With Otomi Stack you’ll get Knative (together with Istio service mesh features) pre-installed and configured. Flux will be available in the next release for automated CD.

Otomi Stack values offers an extra abstraction layer, enabling you to use Knative and Istio without the need to dive deep into all the configuration details, enabling you to concentrate on writing amazing applications. The new release of Otomi Stack will also offer an UI to add and edit the values.

Let's get in touch!

Contact us