0% found this document useful (0 votes)
47 views7 pages

10 Secrets666

The document provides concise notes on using Environment Variables, ConfigMaps, and Secrets in Kubernetes. It explains how to set environment variables in pods, create ConfigMaps for non-sensitive data, and create Secrets for sensitive information, including examples in YAML format. Additionally, it compares ConfigMaps and Secrets regarding their features and usage.

Uploaded by

ValiS1234
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views7 pages

10 Secrets666

The document provides concise notes on using Environment Variables, ConfigMaps, and Secrets in Kubernetes. It explains how to set environment variables in pods, create ConfigMaps for non-sensitive data, and create Secrets for sensitive information, including examples in YAML format. Additionally, it compares ConfigMaps and Secrets regarding their features and usage.

Uploaded by

ValiS1234
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Here are concise notes on **Environment Variables, ConfigMaps, and Secrets** in Kubernetes.

---

# **Environment Variables, ConfigMaps, and Secrets in Kubernetes**

## **1. Environment Variables in Kubernetes**

Environment variables can be used to inject configuration values into containers.

### **Setting Environment Variables in a Pod**

Example:

```yaml

apiVersion: v1

kind: Pod

metadata:

name: env-example

spec:

containers:

- name: my-container

image: busybox

env:

- name: APP_MODE

value: "production"

```

### **Using Environment Variables from a ConfigMap**

```yaml

envFrom:

- configMapRef:

name: my-configmap

```
### **Using Environment Variables from a Secret**

```yaml

envFrom:

- secretRef:

name: my-secret

```

---

## **2. ConfigMaps in Kubernetes**

A **ConfigMap** is used to store non-sensitive configuration data as key-value pairs.

### **Creating a ConfigMap**

#### **Using YAML**

Here are concise notes on **Environment Variables, ConfigMaps, and Secrets** in Kubernetes.

---

# **Environment Variables, ConfigMaps, and Secrets in Kubernetes**

## **1. Environment Variables in Kubernetes**

Environment variables can be used to inject configuration values into containers.

### **Setting Environment Variables in a Pod**

Example:

```yaml

apiVersion: v1

kind: Pod

metadata:

name: env-example
spec:

containers:

- name: my-container

image: busybox

env:

- name: APP_MODE

value: "production"

```

### **Using Environment Variables from a ConfigMap**

```yaml

envFrom:

- configMapRef:

name: my-configmap

```

### **Using Environment Variables from a Secret**

```yaml

envFrom:

- secretRef:

name: my-secret

```

---

## **2. ConfigMaps in Kubernetes**

A **ConfigMap** is used to store non-sensitive configuration data as key-value pairs.

### **Creating a ConfigMap**

#### **Using YAML**

```yaml
```yaml

apiVersion: v1

kind: ConfigMap

metadata:

name: my-configmap

data:

APP_MODE: "production"

LOG_LEVEL: "debug"

```

#### **Using `kubectl`**

```sh

kubectl create configmap my-configmap --from-literal=APP_MODE=production --from-


literal=LOG_LEVEL=debug

```

### **Using a ConfigMap in a Pod**

#### **As Environment Variables**

```yaml

env:

- name: APP_MODE

valueFrom:

configMapKeyRef:

name: my-configmap

key: APP_MODE

```

#### **As a Mounted Volume**

```yaml

volumes:
- name: config-volume

configMap:

name: my-configmap

volumeMounts:

- mountPath: "/etc/config"

name: config-volume

```

---

## **3. Secrets in Kubernetes**

A **Secret** is used to store sensitive data like passwords, tokens, and certificates.

### **Creating a Secret**

#### **Using YAML**

```yaml

apiVersion: v1

kind: Secret

metadata:

name: my-secret

type: Opaque

data:

DB_PASSWORD: cGFzc3dvcmQ= # Base64-encoded value of "password"

```

#### **Using `kubectl`**

```sh

kubectl create secret generic my-secret --from-literal=DB_PASSWORD=password

```

### **Using a Secret in a Pod**


#### **As Environment Variables**

```yaml

env:

- name: DB_PASSWORD

valueFrom:

secretKeyRef:

name: my-secret

key: DB_PASSWORD

```

#### **As a Mounted Volume**

```yaml

volumes:

- name: secret-volume

secret:

secretName: my-secret

volumeMounts:

- mountPath: "/etc/secret"

name: secret-volume

```

---

## **Comparison: ConfigMap vs Secret**

| Feature | ConfigMap | Secret |

|-----------------|-------------------------|--------|

| Stores | Non-sensitive data | Sensitive data (passwords, keys) |

| Data Encoding | Plain text | Base64-encoded |

| Usage | Environment variables, volumes | Environment variables, volumes |

| Security | No encryption | Base64-encoded but not encrypted |


---

These notes provide a **quick reference** for using **environment variables, ConfigMaps, and
Secrets** in Kubernetes. Let me know if you need **more details or examples**! 🚀

You might also like