In this lab, you will create and deploy a mutating webhook, along with its configuration. First, you will create the webhook Docker image from the provided code. Then, you will update the webhook deployment Terraform code with the image and deploy the mutating webhook. Next, you will apply the webhook registration code to finish up the deployment. Finally, you will create a couple of test Pods to confirm your mutating webhook is working as expected.
Learning Objectives
Successfully complete this lab by achieving the following learning objectives:
- Lab Setup
Move to the
mutating-admission-webhook
directory.Create an access key in the AWS Management Console. (You need to copy the Access key and Secret access key and keep them somewhere safe and accessible for the next step).
Make the
lab-setup.sh
script executable.Run the
lab-setup.sh
script. (Note: This script will run for about 10–15 minutes.)
- Create the Webhook Docker Image
Note: Make sure you have set up your Docker Hub account before doing this objective.
Move into the
mutating-webhook
directory.Log in to Docker Hub from the command line.
Update the
Makefile
with your Docker Hub username.Build the mutating webhook. (Note: This can take between 5–10 minutes.)
Build the Docker image.
Push the Docker image to Docker Hub.
Deploy the required certificates.
- Deploy the Mutating Webhook Configuration and Webhook
Update the deployment configuration with your Docker Hub username.
Initialize the working directory.
Apply the configuration.
- Test the Mutating Admission Webhook
Create a directory called
test-pods
.Move into to
test-pods
directory.Use the sample Terraform code to create two test Pods called
test-app-1
andtest-app-2
, and add a label calledhello = "universe"
totest-app-2
.Initialize your working directory.
Apply the webhook configuration.
Confirm that your mutating webhook is working:
test-app-1
should have ahello=world
label, even though one was not provided in the configuration.test-app-2
should have ahello=universe
label, as you defined in the configuration.