secrets

If you know the configMap concepts, then it would be easy to follow along the secrets.

1. Secrets using Imperative

    kubectl create secret generic secretdemo --from-literal nginx_password=iam7hills


2. Secrets using Declarative/Manifest file

secrets.yaml

apiVersion: v1
kind: Secret
metadata:
  name: secretdemo
type: Opaque
data:
  nginx_password: aWFtN2hpbGxz

Execute this command : kubectl create -f secrets.yaml

3. How to inject Secrets into Pods/Deployment yaml

cat podssecretdemo.yaml

apiVersion: v1
kind: Pod
metadata:
  name: podssecretdemo
spec:
  volumes:
  - name: volumemap
    secret:
      secretName: secretdemo
  containers:
  - image: iam7hills/learnkubernetes:podsdemo-1.0
    name: podssecretdemo
    imagePullPolicy: Always
    volumeMounts:
    - name: volumemap
      mountPath: /iam7hills

kubectl exec -it podssecretdemo /bin/sh
kubectl exec [POD] [COMMAND] is DEPRECATED and will be removed in a future version. Use kubectl exec [POD] -- [COMMAND] instead.
/ # cd /iam7hills
/iam7hills # ls -lrt
total 0
lrwxrwxrwx    1 root     root            21 Dec 28 08:09 nginx_password -> ..data/nginx_password
/iam7hills # cat nginx_password
iam7hills