- Cloud Native Applications
- Application Security
- Application Security
- Web Application Security
- Application Security Posture Management (ASPM)
- Microsegmentation
- Python Security
- SaaS Security
- Node.JS Security
- PHP Security
- AI in Cyber Security
- Cybersecurity for Financial Services
- The Principle of Least Privilege (PoLP)
- Identity and Access Management
- Cybersecurity in Banking
- Threat Detection and Response
- Cyber Kill Chain
- Threat Hunting
- Zero Trust Security
- Zero Trust Architecture
- Fileless Attacks
- DSPM
- Container Scanning
- Kubernetes
- Kubernetes
- Kubernetes Alternatives
- Kubernetes Namespace
- Kubernetes Architecture
- Kubernetes Cluster
- Kubernetes Nodes
- Kubernetes Pods
- Kubernetes Jobs
- Kubernetes Workloads
- Kubernetes Monitoring
- Kubernetes Security
- Kubernetes RBAC
- Secret Scanning
- Kubernetes Security Posture Management (KSPM)
- Kubernetes on AWS
- Kubernetes on VMware
- Kubernetes Vulnerability Scanning
- Managing Containers in Kubernetes
- K3s
- eBPF in Kubernetes
- Kubernetes Dashboard
- Kubernetes Operators
- Kubernetes Services
- Kubernetes Devops
- Kubernetes Networking
- Kubernetes ConfigMap
- Kubernetes Management
- Kubernetes Helm
- Kubernetes as a Service
- Kubernetes Serverless
- Kubernetes Tutorials
- Cloud Attacks
- Cloud Attacks
- Malware Attacks
- Zero Day Attack
- Top 10 Cyber Security Threats
- Arbitrary Code Execution
- Cryptojacking
- AI Attacks
- Prompt Injection
- Backdoor Attacks
- Reverse Shell Attack
- Remote Code Execution
- Defense Evasion
- Honeypots in Cybersecurity
- Malware Analysis
- AI Malware
- Lateral Movement
- Advanced Malware Protection
- CNAPP
- AI Security
- Container Platforms
- Containerized Architecture
- Containerized Architecture
- Docker Secrets
- Container Runtime Interface
- Container Images
- Image Scanning
- Container Compliance
- Docker Security Best Practices
- Container Security
- Container Security Best Practices
- Container Security Tools
- ECS Security
- Network Segmentation
- Istio security
- runC
- Service Mesh
- Image Repository
- Container Escape
- Container Runtime
- Docker Container
- OSS Container Image Scanning Tools
- What Is a Container?
- Docker Images
- Containerization 101
- VM vs. Container
- Containerization vs. Virtualization
- Containerized Applications
- Microservices and Containerization
- Registry Scanning
- Docker CVEs
- Docker Monitoring
- Securing Containers with Docker Scanning
- Docker CIS Benchmark
- Seccomp
- Docker Alpine
- Docker API
- Docker Tools
- 100 Best Docker Tutorials
- Docker Alternatives
- Docker Swarm
- Docker Containers vs. Virtual Machines (VMs)
- Docker Architecture
- Docker Networking
- Docker Registries
- Docker Orchestration
- OpenShift vs Docker
- Container Cloud Computing
- Container DevOps
- Docker in Production
- Container Monitoring
- Container Advantages
- Docker Hub
- Serverless Architecture
- Supply Chain Security
- Supply Chain Compliance
- SolarWinds Attack
- Supply Chain Security
- Secure Software Development Lifecycle
- Software Supply Chain Attacks
- Dependency Confusion Attack
- SLSA
- SSDF
- Software Composition Analysis
- Security Misconfigurations
- Repojacking
- Privilege Escalation
- CI/CD Security
- SAST Security
- GitLab Security
- GitHub Secret Scanning
- OWASP Dependency-Check
- Software Bill of Materials
- SBOM Tools
- NPM Vulnerabilities
- Log4j Vulnerability
- Text4Shell
- Secrets Management
- Jenkins Security
- Yarn vs. NPM
- Source Code Leaks
- Container Image Signing
- Open Source Licenses
- Vulnerability Management
- Vulnerability Management Tools
- Vulnerability Scanning Process
- Vulnerability Management
- Vulnerability Scanning
- Vulnerability Prioritization
- Open Source Vulnerability Scanning
- Vulnerability Remediation
- Vulnerability Scanner
- Risk-Based Vulnerability Management
- Vulnerability Exploitability eXchange (VEX)
- Malware Detection
- Fileless Malware
- Attack Vectors
- Malicious Code
- Risk Posture
- Alert Fatigue in Cybersecurity
- Cyber Security Posture
- MITRE ATT&CK
- MITRE ATT&CK Framework
- LLM Security
- Code Scanning
- Attack Surface
- Attack Surface Management
- What Are Indicators of Compromise (IoC)?
- Secure Code
- Configuration Drift
- Trivy
- DevSecOps
- DevSecOps
- DevSecOps Pipeline
- DevSecOps Best Practices
- DevSecOps vs SecDevOps
- Threat Modeling
- Mean Time to Repair (MTTR)
- eBPF Linux
- Cloud DevOps
- DevOps Tools
- GitOps vs DevOps
- Code Security
- Secure Code Review
- DevOps Security
- Infrastructure as Code (IaC) Security
- Infrastructure as Code DevOps
- Executive Order 14028 (U.S. Cybersecurity Executive Order)
- Open Source Security
- Shift-Left Security
- Shift Right Testing and Security
- What Is SecOps (Security Operations)?
- SecDevOps
- DevSecOps Tools
- Linux Security
- Rocky Linux
- Azure DevOps
- Cloud Security
- Cloud Security
- Cloud Security Challenges
- Cloud Security Tools
- Code to Cloud
- Cloud Protection
- Cloud Security Frameworks
- Cloud Security Standards
- Cloud Security Controls
- Cloud Security Posture Management (CSPM)
- AI Workloads
- Cloud Digital Forensics
- Cloud Computing Security Architecture
- What Is Enterprise Cloud Security?
- Virtualized Security
- CSPM Tools
- Vulnerabilities in Cloud Computing
- Top 7 Risks of Cloud Computing
- Cloud Security Assessment
- Cloud Visibility
- Cloud Governance
- Cloud Security Strategy
- Cloud Security Policy
- DFIR
- Cloud Workloads
- Public Cloud Security
- Private Cloud vs. Public Cloud
- Runtime Security
- Azure Cloud Security
- Azure Security Best Practices
- Azure Security vs. AWS Security
- AWS GovCloud: Basics & How It Compares to Azure & GCP
- S3 Security
- Cloud Misconfiguration
- Terraform Security
- Hybrid Cloud Security
- Multi-Cloud Strategy
- Agentless vs. Agent-Based Security & Monitoring
- Cloud Infrastructure Security
- Gartner CSPM
- Cloud Security Scanner
- AWS CIS Benchmark
- Cloud Configuration Management
- Cloud Workload Protection (CWP)
- Cloud Workload Protection Platforms (CWPP)
- Cloud Workload Security
- Cloud Vulnerabilities and Tools that Can Help
- Google Cloud Security
- Shared Responsibility Model
- AWS Shared Responsibility Model
- AWS Cloud Security
- Multi Cloud Security
- Cloud Compliance
- Kubernetes in Production
- Cloud Detection And Response
Kubernetes ConfigMap: Creating, Viewing, Consuming & Managing
>In the world of traditional applications, admins could use environment variables or live input to manage application behavior at runtime. But those approaches don't work well in the realm of Kubernetes workloads – which usually run automatically, meaning they can't accept live input, and which are isolated from their host environment, making it challenging to manage settings via environment variables.
Table of Contents
- What is a Kubernetes ConfigMap?
- Why are ConfigMaps important?
- Managing ConfigMaps
- Updating ConfigMaps
- How to create ConfigMaps
- How to consume ConfigMaps
- Mounting a ConfigMap as a volume
- Injecting a ConfigMap as an environment variable
- Mounting a ConfigMap as a command-line argument
- Using immutable ConfigMaps
- Secrets and ConfigMaps
- Take charge of your Kubernetes clusters
But there’s a solution: ConfigMaps. ConfigMaps make it possible to inject custom data into Kubernetes workloads at runtime, without having to embed it into container images or attempt to set it using environment variables.
Keep reading for a guide to Kubernetes ConfigMaps, including how they work, why they’re important, which risks they can present, and how to manage ConfigMaps effectively.
In this article:
- What is a Kubernetes ConfigMap?
- Why are ConfigMaps important?
- How to create ConfigMaps
- How to consume ConfigMaps
- Managing ConfigMaps
- Updating ConfigMaps
- Using immutable ConfigMaps
- Secrets and ConfigMaps
- Take charge of your Kubernetes clusters
What is a Kubernetes ConfigMap?
In Kubernetes, a ConfigMap is a type of native API object designed to store environment-specific configuration data and share it with Pods (which is a Kubernetes component that runs containers and typically hosts applications).
ConfigMaps store data as key-value pairs. This means you can define virtually any type of object (the key) and set a corresponding value for it using a ConfigMap.
As an example of why and how you might use a ConfigMap, imagine that an application hosted in a Kubernetes Pod needs to connect to a database. To do this, the application must know where to find the database on the network.
You can specify this information using a ConfigMap like the following:
apiVersion: v1
kind: ConfigMap
metadata:
name: database-config
data:
database_URL: "192.168.100.1/database"
database_port: "3306"
This tells the application that the database is available at the URL 192.168.100.1/database, and that it operates on network port 3306.
Why are ConfigMaps important?
ConfigMaps are important because applications often need to access data that can change from one environment to another. For instance, as we mentioned above, an application might need to know where it can locate a database.
Since that data is not consistent between one application deployment and another, hard-coding it into container images wouldn’t make a lot of sense. If you did that, you’d have to rebuild your container images every time the configuration data changed.
Nor is it easy to inject custom configuration data into Kubernetes applications at runtime using approaches that work in other types of setups, like setting environment variables through the command line or using static configuration settings files. Kubernetes Pods aren’t designed to be able to connect easily to these types of resources.
With ConfigMaps, however, admins enjoy an easy, flexible way of declaring environment-specific data. They can create ConfigMaps to define application settings at runtime, and they can update ConfigMaps whenever those settings change.
Managing ConfigMaps
To determine which ConfigMaps exist in your cluster, run:
kubectl get configmaps
This will generate a list of your ConfigMaps.
To view the contents of a ConfigMap, use the command:
kubectl describe configmaps <ConfigMap name>
This will display the keys and values defined in the ConfigMap you specify as a plaintext file, with keys separated by horizontal lines. You can also pass the -o yaml option to kubectl if you want it to display the data using YAML.
Updating ConfigMaps
The easiest way to update a ConfigMap is to use the kubectl edit command. For example:
kubectl edit configmap some-config
This opens up a text editor where you can make changes to the ConfigMap named some-config.
If you mounted the ConfigMap as a volume, the values will update automatically. If you injected the ConfigMap’s values as environment variables or command-line arguments, however, you’ll need to restart the Pods for changes to take effect.
How to create ConfigMaps
Like most Kubernetes resources, ConfigMaps are presented declaratively using code. To create a ConfigMap, simply define an object of the type ConfigMap and specify whichever key-value pairs you want to configure in it.
For example:
apiVersion: v1
kind: ConfigMap
metadata:
name: some-config
data:
value1: "some value"
value2: "another value"
value3: "yet another value"
The example above uses property-like keys. You can also represent key-value pairs using file-like keys, such as the following:
value1=some_value
After writing code for your ConfigMap, save it as a file. Then, use the kubectl create configmap command to create the ConfigMap by referencing the file. For example:
kubectl create configmap app-settings –from-file=app-container/settings/app.properties
This tells Kubernetes to create a ConfigMap named app-settings using the file located at app-container/settings/app.properties.
How to consume ConfigMaps
Once you’ve created a ConfigMap, you can connect it to a Pod using several different approaches. Here’s a look at the most common:
Mounting a ConfigMap as a volume
Mounting ConfigMaps as volumes is a good approach if your ConfigMaps store lots of values and you want to make them accessible to containers through their local file system. This is similar to using a local configuration file to define settings for a traditional app.
Mounting ConfigMaps as volumes also offers the advantage of applying updates automatically. If you change ConfigMap values, the changes will automatically be reflected in your Pod, without requiring it to restart.
To mount a ConfigMap as a volume for a Pod, add a spec to the Pod’s definition that identifies the ConfigMap you want to mount. For example:
spec:
volumes:
- name: config
configMap:
name: some-config
Injecting a ConfigMap as an environment variable
ConfigMaps can be injected as environment variables using the envFrom field, which tells Kubernetes to turn the values inside a specified ConfigMap into environment variables that are accessible to a Pod at runtime.
To do this, include the envFrom field and the appropriate ConfigMap definition in your spec. For example:
spec:
containers:
- name: app
command: ["/bin/command", "-e", "value"]
image: some_app:latest
envFrom:
- configMapRef:
name: some-config
Importantly, ConfigMap values determined as environment variables won’t automatically update if the ConfigMap changes after a container has started. You need to restart the container or Pod for changes to take effect.
Mounting a ConfigMap as a command-line argument
If you want to use values inside a ConfigMap as part of a command that runs inside a Pod, you can mount ConfigMaps as command-line arguments. To do this, write a spec section for your Pod that includes a variable and defines its value based on a ConfigMap. For example:
spec:
containers:
- name: app
command: ["some-app", "--example-variable", "$(VAR_VALUE)"]
image: demo-app:latest
env:
- name: sample_app
valueFrom:
configMapKeyRef:
name: some-config
key: var_value
This tells Kubernetes that the value of the command-line argument —example-variable is specified based on the value of the key var_value which exists in the ConfigMap named some-config.
Note that like ConfigMap values that are injected using environment variables, ConfigMaps values mounted as command-line arguments aren’t automatically updated if the values change after a container or Pod has started.
Using immutable ConfigMaps
Starting with Kubernetes version 1.19, you can configure a ConfigMap to be immutable at the time you create it. This prevents admins from modifying ConfigMap values using the built-in editor. (It could still be possible to modify a ConfigMap using an external editor, then delete and recreate the ConfigMap.)
Immutable ConfigMaps are useful in situations where a ConfigMap stores essential configuration data that should never change and you want to prevent accidental changes from disrupting application performance.
To make a ConfigMap immutable, simply add the following field when creating the ConfigMap:
immutable: true
Secrets and ConfigMaps
While ConfigMaps are a convenient way of injecting various types of configuration data into applications at runtime, there is one type of data you should never manage using ConfigMaps: Secrets, such as passwords, API keys or other access information.
While it’s technically possible to use ConfigMaps to store secrets, doing so creates Kubernetes security risks because anyone who is able to view your ConfigMap will be able to access your secrets. A better approach is to use the secrets management tooling built into Kubernetes.
Take charge of your Kubernetes clusters
As a cloud-native security solution purpose-built for protecting platforms like Kubernetes, Aqua helps keep your clusters and Pods secure, no matter how you configure them. We won’t tell you how to manage your ConfigMaps, but we will provide the visibility you need to identify and mitigate security risks across all layers of your stack.
Learn more by requesting a demo.
- What Is Kubernetes?
- 10 Kubernetes Alternatives and Why You Need Them
- Kubernetes Namespace
- Kubernetes Architecture
- Kubernetes Cluster: 11 Key Components
- Kubernetes Nodes: Components and Basic Operations
- Kubernetes Pods
- Kubernetes Jobs: A Practical Guide
- What Are Kubernetes Workloads, How They Work, and Security Tips
- Kubernetes Monitoring: Metrics, Challenges, and Best Practices
- Kubernetes Security
- Kubernetes RBAC: Why You Need It and 4 Tips for Success
- How Secret Scanning Works and 4 Places to Scan for Secrets
- Kubernetes Security Posture Management (KSPM)
- Kubernetes on AWS
- Kubernetes on VMware: What are the Options?
- Kubernetes Vulnerability Scanning: What You Should Know
- Managing Containers in Kubernetes
- What is K3s? Architecture, Setup, and Security
- eBPF in Kubernetes: Improving Observability for K8s Clusters
- Kubernetes Dashboard: Ultimate Quick Start Guide
- Kubernetes Operators: How they Work and 6 Operators to Try
- Kubernetes Services
- Kubernetes Devops
- Kubernetes Networking
- Kubernetes Management
- Kubernetes Helm
- Top 6 Kubernetes as a Service Providers and Why You Need Them
- Kubernetes Serverless
- 70 Best Kubernetes Tutorials
- Show more
Aqua Cloud Native Application Protection Platform (CNAPP)
Go cloud native with the experts!