Giter VIP home page Giter VIP logo

kubernetes-info-webhook's Introduction

Purpose

To make it easier to create / deploy Kubernetes Mutating WebHook applications

What does the typical Mutating Webhook application look like

The purpose of the mutating webhook is to "mutate" Kubernetes objects. Essentially such an application is a normal Kubernetes application (albeit with some requirements that will be mentioned later) that is called by Kubernetes under certain conditions.

In order for an application to be a valid Mutating Webhook application the following prerequisites need to be met

  • The application needs to be accessible via Kubernetes Service object on port 443
  • The application needs to accept an AdmissionReview object and return a new AdmissionReview object that contains an AdmissionResponse whose most important field is the jsonpatch that needs to be applied to the incoming object
  • The certificate used by the application for the HTTPS communication (initiated by Kubernetes to the application) needs to be trusted by the cluster
  • A MutatingWebhookConfiguration needs to be deployed to the cluster containing configuration of what kind of Requests the mutating webhook will handle as well as the certificate caBundle

Prerequisites

The cluster allows mutating webhooks

For minishift the following command can be run to enable such capability

 minishift openshift config set --target master --patch '{ "admissionConfig": { "pluginConfig": { "MutatingAdmissionWebhook": { "configuration": {  "apiVersion": "v1",  "disable": false,  "kind": "DefaultAdmissionConfig" } } } }, "kubernetesMasterConfig": { "controllerArguments": { "cluster-signing-cert-file": [ "ca.crt" ], "cluster-signing-key-file": [ "ca.key" ] } } }'

Preparation (these steps need to be run by a user that is logged in to the cluster and has the cluster-admin role)

oc new-project k8s-info
./create-signed-cert.sh
./create-default-configmaps.sh
./create-service-account.sh

These steps will create the following:

  • A ServiceAccount named kubernetes-info-webhook that contains the view and secret-reader roles in the k8s-info namespace
  • A secret named kubernetes-info-webhook that contain the certificate and private key needed for HTTPS communication between the application and the cluster. This secret is read by an init container when the application runs in order to create the keystore that Tomcat needs to implement for HTTPS
  • A ConfigMap named k8s-info-configuration that contains the application configuration which is read when the application starts
  • A ConfigMap named k8s-info-mutating-script that contains the actual script that will mutate the incoming object

Configuration

Pay special attention to the values of policy and matchingAnnotation in KubernetesInfoProperties The values you specify for these fields determine which objects will be mutated

Specifically, if policy is enabled, then all objects will be mutated except the ones that contain the value of matchingAnnotation as an annotation with a value of disabled

If it's false, then only objects that contain the value of matchingAnnotation as an annotation with a value of enabled will be mutated

Deployment

./mvnw clean compile fabric8:deploy -Popenshift
./create-default-webhook-configuration.sh

The create-default-webhook-configuration.sh will create a default MutatingWebhookConfiguration

Teardown

./delete-all.sh

TODO

  • Provide configuration options for scripts
  • Provide deployment means other than FMP

kubernetes-info-webhook's People

Contributors

geoand avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Forkers

casi-doc

kubernetes-info-webhook's Issues

What should we do post deployment ....

The README file explains what should be done step-by-step to configure openshift like the resources needed to play with mutating webhook and to deploy the Spring Boot application to reply from HTTP requests coming from Openshift but I don't see instructions how to test/verify if a pod created will be mutated by the webhook after the step

## Deployment 

./mvnw clean compile fabric8:deploy -Popenshift
./create-default-webhook-configuration.sh

Cluster-tole is needed for the openshift's user

Can you update the doc to mention that cluster-admin-role is needed ?

./create-signed-cert.sh
Error from server (Forbidden): error when creating "STDIN": certificatesigningrequests.certificates.k8s.io is forbidden: User "developer" cannot create certificatesigningrequests.certificates.k8s.io at the cluster scope: User "developer" cannot create certificatesigningrequests.certificates.k8s.io at the cluster scope

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.