This template provides a kick start to making a kubernetes admission controller using TypeScript and Node.JS, uses a Validating Webhook.
- Kubernetes-client/client-node
- Jest
- Github Action CI
- Renovate
- Eslint (with standard config)
- Typescript
- Config
- Pino
- Fastify
- InversifyJS
- Sonar Project File
- Dockerfile
The following scripts are included in the NPM project configuration
lintlints the source code using eslintlint:fixautomatically fixes any lint errors that can be fixed automaticallytestuses jest to run test suitestest:e2eruns e2e test suite, this requires an active helm:deploybuildcompiles the typescript into js and places it in thedistfolderbuild:imagebuilds the container imageminikube:startcreate a minikube k8s clusterminikube:stopstop minikube but do not deleteminikube:deletedelete the minikube clusterhelm:addReposadds helm reposhelm:deployCertManagerdeploy cert-manager for TLShelm:deploydeploy the app to k8s using helmhelm:templateprint the k8s yaml that would be applied to k8s when usinghelm:deployhelm:uninstallremove the app from k8shelm:uninstallCertManagerremove cert-manager from the k8s cluster
If you don't already have cert manager installed you will need to run:
helm repo add jetstack https://charts.jetstack.io && helm repo update && \
helm upgrade --install --namespace cert-manager --create-namespace \
cert-manager jetstack/cert-manager --set installCRDs=true --debug --waitFirst add the helm repos helm repo add k8s https://curium-rocks.github.io/k8s-validating-webhook fetch updates helm repo update.
Verify it worked helm search repo k8s and you should see something like.
NAME CHART VERSION APP VERSION DESCRIPTION
k8s/k8s-validating-we... 0.1.0 0.1.0 A starter template for a dynamic admission vali...
Deploy the app helm upgrade --install starter k8s/k8s-validating-webhook
Verify it worked kubectl run testpod --image=badbox you should see an error message like this:
Error from server: admission webhook "starter-k8s-validating-webhook.default.svc" denied the request: One of the images in [badbox] is not allowed, denied
This is meant to include service abstractions, ideally each service should provide an interface/contract exposing the functionality that other things in the application need.
Currently this is setup to house factories or other items to provide instances of third party things/modules that will be bound by the InversifyJS IoC container so they can be injected into other things with @inject()
This houses interfaces/models with little to no logic, the intent is these items can be passed/returned from the abstractions in services and avoid tight coupling to third party types.
This defines symbols for each type that will be configured in the IoC container, these are used to identify the type when using @inject(TYPES.Services.Kubernetes) for example. For more information refer to inversify.
This file maps the types defined in ./src/types.ts to interface types. For more information refer to inversify.
- Update Sonar Project Properties For Sonar Cloud
- Add SONARQUBE_KEY secret to your repo or org if not already present
- Point badges in README.md to correct location for you repo
- Update renovate.json to meet desired behavior for your needs, docs can be found here.
- Update this readme to reflect your project name and info
- Rename all
k8s-validating-webhookreferences to match your project name