Reader small image

You're reading from  The Kubernetes Workshop

Product typeBook
Published inSep 2020
PublisherPackt
ISBN-139781838820756
Edition1st Edition
Right arrow
Authors (6):
Zachary Arnold
Zachary Arnold
author image
Zachary Arnold

Zachary Arnold works as a software engineer at Ygrene Energy Fund. Zach has an experience of over 10 years in modern web development. He is an active contributor to the Open Source Kubernetes project in both SIG-Release and SIG-Docs currently focusing on security. He has been running clusters in production since Kubernetes 1.7 and has spoken at the previous 4 KubeCons. His passion areas in the project center on building highly stable Kubernetes cluster components and running workloads securely inside of Kubernetes.
Read more about Zachary Arnold

Sahil Dua
Sahil Dua
author image
Sahil Dua

Sahil Dua is a software engineer. He started using Kubernetes to run machine learning workloads. Currently, he is running various types of applications on Kubernetes. He shared his learnings as a keynote session at KubeCon Europe 2018. He is a passionate open source contributor and has contributed to some famous projects such as Git, pandas, hound, go-GitHub, and so on. He has been an open source community leader for over 2 years at DuckDuckGo.
Read more about Sahil Dua

Wei Huang
Wei Huang
author image
Wei Huang

Wei Huang: Wei works as a senior software engineer in IBM. He has over 10 years' experiences around database, data warehouse tooling, cloud, container, monitoring and devops. He started to use Kubernetes since 1.3, including extending Kubernetes LoadBalancer using CRD, networking, scheduling and monitoring. Now he is a core maintainer of Kubernetes SIG-Scheduling.
Read more about Wei Huang

Faisal Masood
Faisal Masood
author image
Faisal Masood

Faisal Masood is a cloud transformation architect at AWS. Faisal's focus is to assist customers in refining and executing strategic business goals. Faisal main interests are evolutionary architectures, software development, ML lifecycle, CD and IaC. Faisal has over two decades of experience in software architecture and development.
Read more about Faisal Masood

Mélony Qin
Mélony Qin
author image
Mélony Qin

Mélony Y. QIN, also known as CloudMelon, is the founder of CloudMelon Vis, a tech media and educational platform for technopreneurs in the cloud-native and serverless space, and a former product manager at Microsoft. With a passion for cloud-native technologies, OSS, DevOps, Kubernetes, serverless, data, and AI, Mélony has authored multiple books, including the Certified Kubernetes Administrator (CKA) Exam Guide, the Kubernetes Workshop, and Microsoft Azure Infrastructure, all published by Packt Publishing. Mélony is a member of the Association for Computing Machinery (ACM) and the Project Management Institute (PMI), leveraging her extensive experience with diverse cloud technologies to drive innovation in the cloud-native, serverless, and generative AI space. She runs the CloudMelonVis YouTube channel and Cloud-Native Innovators newsletter, read by professionals from top tech companies such as Microsoft, Google, Amazon, Dell, and Carrefour.
Read more about Mélony Qin

Mohammed Abu Taleb
Mohammed Abu Taleb
author image
Mohammed Abu Taleb

Mohammed Abu-Taleb works as a Technical Advisor at Microsoft. Working at Microsoft CSS team for troubleshooting complex issues and cases for premier customers that are using Azure Kubernetes Services (AKS). Prior that, Mohammed was a SME (subject matter expert) for the azure managed monitoring service (Azure Monitor) focusing on designing, deploying, and troubleshooting monitoring strategies for containers.
Read more about Mohammed Abu Taleb

View More author details
Right arrow

10. ConfigMaps and Secrets

Overview

In this chapter, we will learn how to decouple application configuration data from the application itself and the advantages of taking this approach. By the end of this chapter, you will be able to define Kubernetes ConfigMap and Secret objects, run a simple Pod that uses data from ConfigMaps and Secrets, describe the advantages of decoupling configuration data from applications, and use ConfigMaps and Secrets to decouple application configuration data from the application container.

Introduction

In Chapter 5, Pods, we learned that Pods are the minimal unit of deployment in Kubernetes. Pods can have multiple containers, and each container can have a container image associated with it. This container image generally packages the target application that you plan to run. Once the developers are satisfied that the code is running as expected, the next step is to promote the code to testing, integration, and production environments.

Easy, right? One problem, however, is that as we move our packaged container from one environment to another, although the application remains the same, it needs environment-specific data, for example, the database URL to connect to. To overcome this problem, we can write our applications in such a way that the environment-specific data is provided to the application by the environment it is being deployed into.

In this chapter, we will discover what Kubernetes provides to associate environment-specific data with our application...

What Is a ConfigMap?

A ConfigMap allows us to define application-related data. A ConfigMap decouples the application data from the application so that the same application can be ported across different environments. It also provides a way to inject customized data into running services from the same container image.

ConfigMaps can be created through a literal value or from a file or all the files in a directory. Note that the primary data we stored in ConfigMaps is for non-sensitive configuration, for example, config files or environment variables.

Once a ConfigMap is defined, it will be loaded to the application via an environment variable or a set of files. The application can then see the files as local files and can read from them. It is important to note that (from 1.9.6 version onward of Kubernetes), files loaded from ConfigMaps are read-only. ConfigMaps can also hold configuration data for system applications such as operators and controllers.

In the following exercises...

What Is a Secret?

A ConfigMap provides a way to decouple application configuration data from the application itself. However, the problem with a ConfigMap is that it stores the data in plain text as a Kubernetes object. What if we want to store some sensitive data such as a database password? Kubernetes Secret provides a way to store sensitive data that can then be made available to the applications that require it.

Secret versus ConfigMap

You can think of a Secret as the same as a ConfigMap with the following differences:

  1. Unlike a ConfigMap, a Secret is intended to store a small amount (1 MB for a Secret) of sensitive data. A Secret is base64-encoded, so we cannot treat it as secure. It can also store binary data such as a public or private key.
  2. Kubernetes ensures that Secrets are passed only to the nodes that are running the Pods that need the respective Secrets.

    Note

    Another way to store sensitive data is a vault solution, such as HashiCorp Vault. We have left such...

Summary

In this chapter, we have seen the different ways that Kubernetes provides to associate environment-specific data with our applications running as containers.

Kubernetes provides ways to store sensitive data as Secrets and normal application data as ConfigMaps. We have also seen how to create ConfigMaps and Secrets and associate them with our containers via CLI. Running everything via the command line will facilitate the automation of these steps and improve the overall agility of your application.

Associating data with containers enables us to use the same container across different environments in our IT systems (for example, in test and production). Using the same container across different environments provides a way for secure and trusted code promotion techniques for IT processes. Each team can use a container as a unit of deployment and sign the container so that other parties can trust the container. This also provides a trusted way of distributing code not...

lock icon
The rest of the chapter is locked
You have been reading a chapter from
The Kubernetes Workshop
Published in: Sep 2020Publisher: PacktISBN-13: 9781838820756
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Authors (6)

author image
Zachary Arnold

Zachary Arnold works as a software engineer at Ygrene Energy Fund. Zach has an experience of over 10 years in modern web development. He is an active contributor to the Open Source Kubernetes project in both SIG-Release and SIG-Docs currently focusing on security. He has been running clusters in production since Kubernetes 1.7 and has spoken at the previous 4 KubeCons. His passion areas in the project center on building highly stable Kubernetes cluster components and running workloads securely inside of Kubernetes.
Read more about Zachary Arnold

author image
Sahil Dua

Sahil Dua is a software engineer. He started using Kubernetes to run machine learning workloads. Currently, he is running various types of applications on Kubernetes. He shared his learnings as a keynote session at KubeCon Europe 2018. He is a passionate open source contributor and has contributed to some famous projects such as Git, pandas, hound, go-GitHub, and so on. He has been an open source community leader for over 2 years at DuckDuckGo.
Read more about Sahil Dua

author image
Wei Huang

Wei Huang: Wei works as a senior software engineer in IBM. He has over 10 years' experiences around database, data warehouse tooling, cloud, container, monitoring and devops. He started to use Kubernetes since 1.3, including extending Kubernetes LoadBalancer using CRD, networking, scheduling and monitoring. Now he is a core maintainer of Kubernetes SIG-Scheduling.
Read more about Wei Huang

author image
Faisal Masood

Faisal Masood is a cloud transformation architect at AWS. Faisal's focus is to assist customers in refining and executing strategic business goals. Faisal main interests are evolutionary architectures, software development, ML lifecycle, CD and IaC. Faisal has over two decades of experience in software architecture and development.
Read more about Faisal Masood

author image
Mélony Qin

Mélony Y. QIN, also known as CloudMelon, is the founder of CloudMelon Vis, a tech media and educational platform for technopreneurs in the cloud-native and serverless space, and a former product manager at Microsoft. With a passion for cloud-native technologies, OSS, DevOps, Kubernetes, serverless, data, and AI, Mélony has authored multiple books, including the Certified Kubernetes Administrator (CKA) Exam Guide, the Kubernetes Workshop, and Microsoft Azure Infrastructure, all published by Packt Publishing. Mélony is a member of the Association for Computing Machinery (ACM) and the Project Management Institute (PMI), leveraging her extensive experience with diverse cloud technologies to drive innovation in the cloud-native, serverless, and generative AI space. She runs the CloudMelonVis YouTube channel and Cloud-Native Innovators newsletter, read by professionals from top tech companies such as Microsoft, Google, Amazon, Dell, and Carrefour.
Read more about Mélony Qin

author image
Mohammed Abu Taleb

Mohammed Abu-Taleb works as a Technical Advisor at Microsoft. Working at Microsoft CSS team for troubleshooting complex issues and cases for premier customers that are using Azure Kubernetes Services (AKS). Prior that, Mohammed was a SME (subject matter expert) for the azure managed monitoring service (Azure Monitor) focusing on designing, deploying, and troubleshooting monitoring strategies for containers.
Read more about Mohammed Abu Taleb