Inject secret as env variable


vim envsecret.yaml


apiVersion: v1
kind: Pod
metadata:
	name: firstPod
spec:
	containers:
		- image: image:latest
		  name: firstcontainer
		  env:
			name:myvariable
			valueFrom:
				secretKeyRef:
					key: variable1
					name: myenvsec


kubectl apply -f envsecret.yaml


the above command will create a pod and it will have our secret value. Now we will execute the above-created pod and use kubectl exec command and when we use the env command we will be able to see the secret which we inserted in the env list


To inject multiple secret


vim multisecret.yaml


apiVersion: v1
kind: Pod
metadata:
	name: firstPod
spec:
	containers:
		- image: image:latest
		  name: firstcontainer
		  envFrom:
			secretKeyRef:
					name: myenvsec


kubectl apply -f multisecret.yaml

we can use the above YAML file to inject multiple secret values inside the pod


Inject secret as file


vim injectfilesecret.yaml


apiVersion: v1
kind: Pod
metadata:
	name: firstPod
spec:
	containers:
		- image: image:latest
		  name: firstcontainer
		  volumeMounts:
			- mountPath: /secrets
			  name: volumename
	volumes:
	  - name : vaolumename
        - secret
		   mysecretName: mysecretenv


kubectl apply -f injectfilesecret.yaml


in the above YAML file definition, we have mounted one volume and that volume contains a secret name mysecretenv file, we can use this in our pod definition to inject secret as a file