8000 GitHub - akosbalogh005/easyhttp-operator: Kubernetes operator for deploying HTTP application easily
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

akosbalogh005/easyhttp-operator

Repository files navigation

CI Docker

easyhttp

Kuberneres Operator. The main purpose of this operator to easy deploy HTTP application your kubernetes cluster. Currently this is my best operator, since it is my first one :)

Description

The operator exposes the HTTP port and setup all necessary resources in the cluster. The owner of the created resource is the EasyHttp oprator.

Main features:

  • Creates deployment, service and ingress resource in cluster
  • Setup host based virtual hosting in ingress host-based hosting
  • Support multiple HTTP application with different path (prefix) in the same host
  • Support specification changes
  • Environment variables in application container can be setup

Managed resources (green): DAST OPERATOR

Limitation

The rewrite possibility is missing from ingress. One host per application can be deployed.

Prerequirements

ingress

By default ingress is not installed in k8s. In order to setup proper host based routing ingress controlled should be existed in cluster.

See ingress here

Check if ingress and issuers are exsisted:

Check Custom resources:

$ kubectl get crd | grep -i issue
clusterissuers.cert-manager.io        2023-03-26T12:01:58Z
issuers.cert-manager.io               2023-03-26T12:01:58Z

The EasyHttp uses namespace scoped issuers so 'issuers.cert-manager.io' should be installed

issuer:

$ kubectl get issuers -n test
NAME                  READY   AGE
letsencrypt-staging   True    57m
letsencrypt-prod      True    50m

The created issuer name should be set in operator kind specification (certManIssuer: "letsencrypt-staging", see later)

Installing ingress see the proper kubernetes implementation details.

When using kind see ingress here

install nginx ingress in kind cluster:

kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/deploy/static/provider/kind/deploy.yaml

certificate manager

Install certificate manager (https://cert-manager.io/) if you want auto certificate manager.

See:

The installation provides HTTP01 challenge

See:

How to install? See: https://cert-manager.io/docs/installation/

install in nutshell:

  1. intall cert-manager
kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.11.0/cert-manager.yaml
  1. create issuer(s)

The samples below shows how to create acme letsencrypt issuer in namespace 'test'. As the operator is namescpase scoped the issuer should create the namesapace where the application is running. One of these should use in kind sepcification (certManIssuer).

kubectl create --edit -f https://raw.githubusercontent.com/cert-manager/website/master/content/docs/tutorials/acme/example/production-issuer.yaml -n test


kubectl create --edit -f https://raw.githubusercontent.com/cert-manager/website/master/content/docs/tutorials/acme/example/staging-issuer.yaml  -n test

Using the operator

sample EasyHttp yml config

apiVersion: httpapi.github.com/v1
kind: EasyHttp
metadata:
  name: kuard-1
  labels:
    app.kubernetes.io/name: easyhttp
    app.kubernetes.io/instance: easyhttp-sample
    app.kubernetes.io/part-of: easyhttp
    app.kubernetes.io/managed-by: kustomize
    app.kubernetes.io/created-by: easyhttp
spec:
  host: "example.net"
  replicas: 1
  image: "gcr.io/kuar-demo/kuard-amd64"
  tag: "1"
  port: 8080
  env:
    PORT: "8080"
  certManIssuer: "letsencrypt-staging"
  path: "/app2"

Description

  • host: The HTTP request to this host will be routed to application
  • replicas: Deployment replicas
  • image: Application docker image
  • tag: image tag
  • port: the HTTP port wher the application is listening
  • env: Environment variable passed to the pod
  • certManIssuer: used certificate issuer
  • path: the application path from outside (will be rewritten to the root of the container)

Installing operator on cluster

The operator can be installed using pre-defined kubernetes configuration. The operator will be installed into 'easyhttp-system' namespace.

The following example install v0.3 of EasyHttp operator (CRD and controller)

kubectl apply -f https://raw.githubusercontent.com/akosbalogh005/easyhttp-operator/0.3/config/easyhttp-operator.yml

The following example install the latest of EasyHttp operator (CRD and controller)

kubectl apply -f https://raw.githubusercontent.com/akosbalogh005/easyhttp-operator/main/config/easyhttp-operator_latest.yml

The git repo is here. The package is stored in ghcr.io repository.

TODO: helm chart repository for easy installation and management

Develping - Getting Started

You’ll need a Kubernetes cluster to run against. You can use KIND to get a local cluster for testing, or run against a remote cluster. Note: Your controller will automatically use the current context in your kubeconfig file (i.e. whatever cluster kubectl cluster-info shows).

Running on the cluster

  1. Install Instances of Custom Resources:
kubectl apply -f config/samples/dep_kuard.yml
  1. Build and push your image to the location specified by IMG:
make docker-build docker-push IMG=<some-registry>/easyhttp:tag
  1. Deploy the controller to the cluster with the image specified by IMG:
make deploy IMG=<some-registry>/easyhttp:tag

Uninstall CRDs

To delete the CRDs from the cluster:

make uninstall

Undeploy controller

UnDeploy the controller from the cluster:

make undeploy

How it works

This project aims to follow the Kubernetes Operator pattern.

It uses Controllers, which provide a reconcile function responsible for synchronizing resources until the desired state is reached on the cluster.

Test It Out

  1. Install the CRDs into the cluster:
make install
  1. Run your controller (this will run in the foreground, so switch to a new terminal if you want to leave it running):
make run

NOTE: You can also run this in one step by running: make install run

Modifying the API definitions

If you are editing the API definitions, generate the manifests such as CRs or CRDs using:

make manifests

NOTE: Run make --help for more information on all potential make targets

More information can be found via the Kubebuilder Documentation

License

Copyright 2023.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

TODOs in the future

The following features / ideas will be implemented in the next version:

  • rewrite functionality with not only nginx ingress conroller
  • Implement more (negative) unittest
  • Implement acceptance tests
  • Releases:
    • create helm chart for operator after tagging
  • filtering of watched namespace

About

Kubernetes operator for deploying HTTP application easily

Resources

Stars

Watchers

Forks

Packages

 
 
 
0