구성을 위한 ConfigMaps 및 Secrets
Kubernetes에서 ConfigMaps와 Secrets를 사용해 애플리케이션 구성과 민감한 데이터를 안전하게 관리합니다.
구성을 위한 ConfigMaps 및 Secrets은(는) CoddyKit의 무료 Docker & Kubernetes for Developers 강의입니다. 이것은 4개 중 3번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Docker & Kubernetes for Developers 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Docker & Kubernetes for Developers 강의에는 총 4개의 강의가 포함되어 있습니다.
이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.
Configuration Challenges
Managing application configuration and sensitive data can be tricky, especially in dynamic environments like Kubernetes.
Hardcoding values into images makes them less reusable. Storing secrets directly in Git is a security risk.
Kubernetes offers two powerful resources to solve these challenges: ConfigMaps and Secrets.
Meet ConfigMaps
A ConfigMap is an API object used to store non-sensitive configuration data in key-value pairs.
Think of it as a central place for settings like database hostnames, logging levels, or API endpoints.
- Separates configuration from application code.
- Allows easy updates without rebuilding images.
- Can be consumed as environment variables or mounted files.
ConfigMap: Literal Values
You can create a ConfigMap directly from literal key-value pairs using YAML. This is great for simple, direct settings.
Here's an example for an application's settings:
apiVersion: v1
kind: ConfigMap
metadata:
name: app-settings
data:
log_level: INFO
feature_flag_a: "true"
api_url: http://backend-service/apiConfigMap: From Files
For more complex configurations, you can create a ConfigMap from an entire file.
If you have a config.properties file, its content can be directly embedded into the ConfigMap. The resulting ConfigMap would look like this:
apiVersion: v1
kind: ConfigMap
metadata:
name: app-config-from-file
data:
config.properties: |
database.host=db-service
database.port=5432
application.name=MyWebAppConfigMap as Env Vars
The most common way to use a ConfigMap is by injecting its data as environment variables into your Pods.
This allows your application to read configuration values directly.
apiVersion: v1
kind: Pod
metadata:
name: my-app-pod
spec:
containers:
- name: my-container
image: nginx
env:
- name: LOG_LEVEL
valueFrom:
configMapKeyRef:
name: app-settings
key: log_level
- name: API_URL
valueFrom:
configMapKeyRef:
name: app-settings
key: api_urlConfigMap as Volume Mounts
ConfigMap data can also be mounted as files into a Pod's filesystem. This is ideal for applications that read configuration from files.
Each key in the ConfigMap becomes a file in the specified mountPath. For example, log_level would be at /etc/config/log_level.
apiVersion: v1
kind: Pod
metadata:
name: my-app-pod-volume
spec:
containers:
- name: my-container
image: nginx
volumeMounts:
- name: config-volume
mountPath: "/etc/config"
volumes:
- name: config-volume
configMap:
name: app-settingsIntroducing Secrets
A Secret is similar to a ConfigMap but is designed for sensitive data like passwords, API keys, or TLS certificates.
Secrets are stored in Kubernetes in base64 encoded format, but this is NOT encryption. It's just encoding for safe transport.
- Provides a mechanism to distribute sensitive data.
- Accessed like ConfigMaps (env vars or volume mounts).
- Should always be managed with care and access controls.
Secret: Literal Values
Secrets are created similarly to ConfigMaps, but their data values are base64 encoded. This encoding is for safe transport, not encryption.
For example, if your password is "my-secure-password", its base64 encoding is "bXktc2VjdXJlLXBhc3N3b3Jk".
apiVersion: v1
kind: Secret
metadata:
name: db-credentials
type: Opaque
data:
username: dXNlcg== # 'user' base64 encoded
password: bXktc2VjdXJlLXBhc3N3b3Jk # 'my-secure-password' base64 encodedSecret as Env Vars
Secrets can be consumed as environment variables, just like ConfigMaps. Kubernetes automatically decodes the base64 value for the container.
This makes sensitive data available to your application without hardcoding it directly in the image.
apiVersion: v1
kind: Pod
metadata:
name: my-db-app
spec:
containers:
- name: my-container
image: my-app:1.0
env:
- name: DB_USERNAME
valueFrom:
secretKeyRef:
name: db-credentials
key: username
- name: DB_PASSWORD
valueFrom:
secretKeyRef:
name: db-credentials
key: passwordSecret as Volume Mounts
Mounting Secrets as files is often preferred for sensitive data, as it limits the exposure of the secret to the application process.
The mounted files will contain the decoded (plain-text) secret values, and you can set them to be read-only.
apiVersion: v1
kind: Pod
metadata:
name: my-secure-app
spec:
containers:
- name: my-container
image: my-app:1.0
volumeMounts:
- name: secret-volume
mountPath: "/etc/secrets"
readOnly: true
volumes:
- name: secret-volume
secret:
secretName: db-credentialsConfigMaps vs. Secrets
You need to store an API key for a third-party service and a configuration setting for your application's logging level. Which Kubernetes resources would you use for each?
Recap: Config & Secrets
We've learned how ConfigMaps and Secrets help manage configuration and sensitive data in Kubernetes.
- ConfigMaps store non-sensitive key-value pairs.
- Secrets store sensitive data, base64 encoded (not encrypted).
- Both can be consumed as environment variables or mounted files in Pods.
- Using them separates configuration from application logic, improving flexibility and security.
AI 튜터와 함께 Docker & Kubernetes for Developers을(를) 배우세요 — 무료
브라우저에서 실제 코드를 작성하고 실행하며, 24/7 AI 튜터로부터 즉각적인 도움을 받고, 웹이나 앱에서 중단한 부분부터 계속 학습하세요.
- 코스
- 12
- 레슨
- 48
자주 묻는 질문
“구성을 위한 ConfigMaps 및 Secrets” 강의는 무료인가요?
네 — “구성을 위한 ConfigMaps 및 Secrets” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Docker & Kubernetes for Developers 강의 전체를 잠금 해제할 수 있습니다. Docker & Kubernetes for Developers 강의에는 총 4개의 강의가 포함되어 있습니다.
“구성을 위한 ConfigMaps 및 Secrets”에서 뭘 배우나요?
Kubernetes에서 ConfigMaps와 Secrets를 사용해 애플리케이션 구성과 민감한 데이터를 안전하게 관리합니다. 브라우저에서 직접 실행하는 실습 코드로 Docker & Kubernetes for Developers을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.
Docker & Kubernetes for Developers을(를) 시작하는 데 경험이 필요한가요?
사전 경험은 필요하지 않습니다. CoddyKit의 Docker & Kubernetes for Developers은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 3번째 강의입니다.
“구성을 위한 ConfigMaps 및 Secrets” 강의는 얼마나 걸리나요?
대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.
이 Docker & Kubernetes for Developers 강의에서 코드를 작성하고 실행할 수 있나요?
네. 모든 Docker & Kubernetes for Developers 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.
이 강의의 모든 강의
- 영구 볼륨 및 영구 볼륨 클레임
- StatefulSets를 활용한 상태 저장 애플리케이션 관리
- 구성을 위한 ConfigMaps 및 Secrets
- StorageClasses와 동적 프로비저닝