Create Your First Kubernetes Operator

45 minutes
  • 4 Learning Objectives

About this Hands-on Lab

Hey, Gurus! Welcome to this hands-on lab. In this lab, we will take what we have learned and build our Kubernetes operator.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Create the Operator Project
  1. Create the operator project directory called memcached-operator in a directory called projects.
  2. Move into the operator project directory that you just created.
  3. Set your GOPATH and enable the Go modules.
  4. Initialize your operator project directory.
Create the API and Controller
  1. Create the API and controller.

    Note: Remember you will need to use additional flags for the memcached image as follows:
    --plugins="deploy-image/v1-alpha" --image=memcached:1.4.36-alpine --image-container-command="memcached,-m=64,modern,-v" --run-as-user="1001"

  2. Edit the api/v1alpha1/memcached_types.go file.
  3. Change the validation marker for the maximum nodes that can be run from 3 to 5.
  4. Update the code.
  5. Generate the CRD manifests and RBAC manifests.
Deploy the Operator
  1. Log in to Docker Hub from the command line.
  2. Create an enviroment variable for your image.
  3. Make the operator image.
  4. Push your operator image to Docker Hub.
  5. Deploy your operator image to the cluster.
  6. Verify that your image was deployed.
Create the Memcached Custom Resource
  1. Create the memcached custom resource from the cache_v1alpha1_memcached.yaml sample file and change the size from 1 to 3.
  2. Apply your CR to the cluster.
  3. Verify the deployment.
  4. Edit the CR and change the size from 3 to 5.
  5. Apply the changes to the CR.
  6. Verify the changes to test and complete the lab.

Additional Resources

In this lab, you will create the operator project. Then, you'll create the API and controller, making a few changes to both. You will then generate the CRD and RBAC manifests to get your operator ready for deployment. You will then build and push your operator image to the Docker Hub image registry. Next, you will deploy your operator to your Kubernetes cluster. To test it, you will create a memcached custom resource, set the spec size to 3 and apply the configuration. You will verify it is working and then change the size to 5 and apply the changes. You will need to confirm the changes to complete the lab.

Good luck, and let's get started with the lab!

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?