Below kubernetes example include ConfigMap, Secret and Volume, added in pod.
Secret data :
User: admin
pass: pass
# echo "admin" | base64
# echo "pass" | base64
Create ConfigMap and Secret imperative way :
kubectl create configmap cname --from-literal=SERVER_URL=https://go.gl
kubectl create secret generic sname --from-literal=user=YWRtaW4K
--from-literal=pass=cGFzcwo=
Create folder and sample "index.html" file:
sudo mkdir /mnt/data
sudo sh -c "echo 'Hello from Kubernetes storage' > /mnt/data/index.html"
Here, Create yml file for PersistentVolume with 100M storage and StorageClass is manual,
refer below:
# kubectl create -f pv.yml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: task-pv-claim
spec:
storageClassName: manual
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 100M
# kubectl create -f pvc.yml
Create Pod with ConfigMap, Secret, Volume :
apiVersion: v1
kind: Pod
metadata:
name: mypod
spec:
volumes:
- name: task-pv-storage
persistentVolumeClaim:
claimName: task-pv-claim
- name: mysecret
secret:
secretName: sname
containers:
- name: task-pv-container
image: nginx
env:
- name: SERVER_URL_ENV
valueFrom:
configMapKeyRef:
name: cname
key: SERVER_URL
volumeMounts:
- name: mysecret
mountPath: "/etc/test"
- name: task-pv-storage
mountPath: "/usr/share/nginx/html"
# kubectl create -f pod.yml
Testing :
$ kubectl exec -it mypod sh
# cat /etc/test/* | base64 -d # Test secret
admin
pass
# env | grep SERVER_URL_ENV # check configMap env variable check
SERVER_URL=https://go.gl
# df -h # Check volume mount & also check with "mount" command
Done !
0 Comments