Passing Configuration Data to a Kubernetes Container

30 minutes
  • 2 Learning Objectives

About this Hands-on Lab

Kubernetes has multiple options for storing and managing configuration data. This lab will focus on the process of passing that configuration data to your containers in order to configure applications. You will have the opportunity to work with application configuration in Kubernetes hands-on by passing some existing configuration data stored in Secrets and ConfigMaps to a container.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Generate an `htpasswd` File and Store It as a Secret

Use htpasswd to generate an htpasswd file.

Create a secret called nginx-htpasswd, and store the contents of the htpasswd file in that Secret. Delete the htpasswd file once the Secret is created.

Create the Nginx Pod

Create a pod with a single container using the nginx-1.19.1 image.

The Nginx configuration is stored in an existing ConfigMap called nginx-config. Mount the ConfigMap to /etc/nginx in your pod.

Mount your htpasswd secret to /etc/nginx/conf within your pod. The htpasswd data should be in a file in the container at /etc/nginx/conf/.htpasswd.

Expose containerPort 80 on the Nginx container so you can communicate with it to test your setup.

Additional Resources

You are working for BeeBox, a company that provides regular shipments of bees to customers. The company is working on deploying some applications to a Kubernetes cluster.

One of these applications is a simple Nginx web server. This server is used as part of a secure backend application, and the company would like it to be configured to use HTTP basic authentication.

This will require an htpasswd file as well as a custom Nginx config file. In order to deploy this Nginx server to the cluster with good configuration practices, you will need to load the custom Nginx configuration from a ConfigMap (this already exists) and use a Secret to store the htpasswd data.

Create a Pod with a container running the nginx-1.19.1 image. Supply a custom Nginx configuration using a ConfigMap, and populate an htpasswd file using a Secret.

htpasswd is already installed on the server, and you can generate an htpasswd file like so:

htpasswd -c .htpasswd user

A pod called busybox already exists in the cluster, which you can use to contact your Nginx pod and test your setup.

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.

Get Started
Who’s going to be learning?

How many seats do you need?

  • $499 USD per seat per year
  • Billed Annually
  • Renews in 12 months

Ready to accelerate learning?

For over 25 licenses, a member of our sales team will walk you through a custom tailored solution for your business.


$2,495.00

Checkout
Sign In
Welcome Back!

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