With ConfigMap
kubectl create configmap myconfig --from-file ./configuration.txt
update:
kubectl create configmap myconfig --from-file ./configuration.txt -o yaml --dry-run | kubectl replace -f -
// deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: YOUR_DEPLOYMENT_NAME
namespace: YOUR_NAMESPACE
labels:
app: YOUR_DEPLOYMENT_NAME
spec:
selector:
matchLabels:
app: YOUR_DEPLOYMENT_NAME
template:
metadata:
labels:
app: YOUR_DEPLOYMENT_NAME
spec:
containers:
- name: YOUR_DEPLOYMENT_NAME
image: YOUR_IMAGE_NAME
imagePullPolicy: Always
volumeMounts:
- name: config
mountPath: /etc/config
volumes:
- name: config
configMap:
name: myconfig
kubectl apply -f deployment.yaml
path:
/etc/config/configuration.txt
With secret
convert password
$ echo -n "testpassword" | base64
dGVzdA==
// secrets.yaml
apiVersion: v1
kind: Secret
metadata:
name: mysecret
type: Opaque
data:
DB_PASSWORD: dGVzdA==
kubectl apply -f secrets.yaml
kubectl describe secret/mysecret
// deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: YOUR_DEPLOYMENT_NAME
namespace: YOUR_NAMESPACE
labels:
app: YOUR_DEPLOYMENT_NAME
spec:
selector:
matchLabels:
app: YOUR_DEPLOYMENT_NAME
template:
metadata:
labels:
app: YOUR_DEPLOYMENT_NAME
spec:
containers:
- name: YOUR_DEPLOYMENT_NAME
image: YOUR_IMAGE_NAME
envFrom:
- secretRef:
name: mysecret
imagePullPolicy: Always
kubectl apply -f deployment.yaml
with nodejs
const password = process.env.DB_PASSWORD?process.env.DB_PASSWORD:"default_password"