A basic K8s operator built with kubebuilder, aims to make deploying web applications easier. WebApp Operator makes a new resource called WebApp available for deployment on K8s clusters. The creation of WebApp means the creation of three other resources behind the scenes:
- Deployment
- Service
- Ingress
After a WebApp is created, the deployed application is available on the host defined by the user.
- go1.16.4
- Cluster
- NGINX Ingress Controller
- Cert-manager with cluster issuer named
letsencrypt-staging
Clone the repository, cd into it, connect to a K8s cluster, then run
make
make install
make deploy IMG=gomba999/webapp-operator:latest
As an alternative to deploying WebApp to the cluster, it can run locally against it after installing it:
make run ENABLE_WEBHOOKS=false
After these steps the CRDs used by the WebApp operator are installed in the cluster and the operator is running. Next, a sample WebApp can be started by running
kubectl create --edit -f config/samples/app_v1_webapp.yaml
Please edit the host to suit your case. By visiting the host in a web browser you should see the NGINX Welcome screen.
When creating a WebApp, you have to have the following fields in the spec section:
// example from config/samples/app_v1_webapp.yaml
spec:
image: "nginx:1.14.2" // image used by the deployment
replicas: 2 // number of replicas created by the deployment
host: "app-kolonits-dominik-hw.spotguidetest.alpha.dev.banzaicloud.com" // host used by the ingress
There's one optional field too, containerPort. With containerPort you can define which port the image provided uses, the default value for this field is 80.
Travis is used as a CI. Currently it is triggered by pushing changes to the repository, either to branches or PRs. Every build pushes a new version of the Docker image to Docker Hub with the latest tag. When a tag is pushed to a branch, it is used as a new image tag too.