简体   繁体   中英

Data from volumes as kubernetes secrets

I have an application that starts with docker-compose up . Some ssh credentials are provided with a json file, in a volume, in the host machine. I want to run the app in kubernetes, how can I provide the credentials using kubernetes secrets? my json file looks like:

{
  "HOST_USERNAME"="myname",
  "HOST_PASSWORD"="mypass",
  "HOST_IP"="myip"
}

I created a file named mysecret.yml with base64 and I applied in kubernetes

apiVersion: v1
kind: Secret
metadata:
  name: mysecret
type: Opaque
data:
  HOST_USERNAME: c2gaQ=
  HOST_PASSWORD: czMxMDIsdaf0NjcoKik=
  HOST_IP: MTcyLjIeexLjAuMQ==

How I have to write the volumes in deployment.yml in order to use the secret properly?

apiVersion: v1
kind: Pod
metadata:
  name: mypod
spec:
  containers:
  - name: mypod
    image: redis
    volumeMounts:
    - name: foo
      mountPath: "/etc/foo"
      readOnly: true
  volumes:
  - name: foo
    secret:
      secretName: mysecret

This is the above example of using secret as volumes. You can use the same to define a deployment.

Please refer to official kubernetes documentation for further info: https://kubernetes.io/docs/concepts/configuration/secret/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM