esphen / naiserator

Naiserator creates a full set of Kubernetes application infrastructure based on a single application spec.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Naiserator

Github Actions Go Report Card

Naiserator is a Kubernetes operator that handles the lifecycle of the custom resource nais.io/Application. The main goal of Naiserator is to simplify application deployment by providing a high-level abstraction tailored for the NAIS platform. Naiserator supersedes naisd.

When an Application resource is created in Kubernetes, Naiserator will generate several resources that work together to form a complete deployment:

  • Deployment that runs a specified number of application instances
  • Service which points to the application endpoint
  • Horizontal pod autoscaler for automatic application scaling
  • Service account for granting correct permissions to managed resources

Optionally, if enabled in the application manifest, the following resources:

  • Ingress adding TLS termination and virtualhost support
  • Leader election sidecar which decides a cluster leader from available pods. This feature also creates a Role and Role binding.

These resources will remain in Kubernetes until the Application resource is deleted. Any unneeded resources will be automatically deleted if disabled by feature flags or is lacking in a application manifest.

Documentation

The entire specification for the manifest is documented in our doc.nais.io.

Deployment

Installation

You can deploy the most recent release of Naiserator by applying to your cluster:

kubectl apply -f hack/resources/

Development

  • The Go programming language, version 1.11 or later
  • goimports
  • Docker Desktop or other Docker release compatible with Kubernetes
  • Kubernetes, either through minikube or a local cluster

Go modules are used for dependency tracking. Make sure you do export GO111MODULE=on before running any Go commands. It is no longer needed to have the project checked out in your $GOPATH.

kubectl apply -f ../liberator/config/crd
kubectl apply -f ./hack/resources
make local

Kafka & Protobuf

Whenever an Application is synchronized, a deployment event message can be sent to a Kafka topic. There's a few prerequisites to develop with this enabled locally:

  1. Protobuf installed
  2. An instance of kafka to test against. Use docker-compose up to bring up a local instance.
  3. Enable this feature by passing -kafka-enabled=true when starting Naiserator.

Update and compile Protobuf definition

Whenever the Protobuf definition is updated you can update using make proto. It will download the definitions, compile and place them in the correct packages.

Code generation

In order to use the Kubernetes Go library, we need to use classes that work together with the interfaces in that library. Those classes are mostly boilerplate code, and to ensure healthy and happy developers, we use code generators for that.

When the CRD changes, or additional Kubernetes resources need to be generated, you have to run code generation:

make crd
make codegen-crd
make codegen-updater
git add -A
git commit -a -m "Update boilerplate k8s API code"

controller-gen

The tool controller-gen is used by make crd to generate a CRD YAML file using the Go type specifications in pkg/apis/nais.io/v1alpha1/*_types.go. This YAML file should not be edited by hand. Any changes needed should go directly into the Go file as magic annotations.

The CRD spec will be generated in config/crd/nais.io_applications.yaml.

Check out the controller-gen documentation if unsure.

A known working version of controller-gen is v0.2.5. Download with

GO111MODULE=off go get sigs.k8s.io/controller-tools/cmd/controller-gen@v0.2.5

About

Naiserator creates a full set of Kubernetes application infrastructure based on a single application spec.

License:MIT License


Languages

Language:Go 98.7%Language:Makefile 0.5%Language:Smarty 0.5%Language:Dockerfile 0.2%Language:Shell 0.1%