I’m beginner in Kubernetes, what I would like to achieve is :
- Pass user’s ssh private/public key to the Pod and then to the Docker container (there’s a shell script that will be using this key)
So I would like to know if it’s possible to do that in the Kubectl apply ?
My pod.yaml looks like :
apiVersion: v1
kind: Pod
metadata:
generateName: testing
labels:
type: testing
namespace: ns-test
name: testing-config
spec:
restartPolicy: OnFailure
hostNetwork: true
containers:
- name: mycontainer
image: ".../mycontainer:latest"
2
Answers
First, you create a secret with your keys:
kubectl create secret generic mysecret-keys --from-file=privatekey=</path/to/the/key/file/on/your/host> --from-file=publickey=</path/to/the/key/file/on/your/host>
Then you refer to the key files using the secret in your pod:
You can check the secret with
kubectl get secret mysecret-keys --output yaml
. You can check the pod and its mounting withkubectl describe pod testing-config
.you have to store the private / public key in a kubernetes secret object
and now you can mount this secret file in your container:
The documentation of kuberentes provides also an chapter of Using Secrets as files from a Pod
It’s not tested but i hope it works.