Kuberentes: How to use ssh secret key file?

0 votes

I'm trying to use the id_rsa file as a secret inside a container. So I create as secret out of it using kubectl:

kubectl create secret generic hcom-secret --from-file=ssh-privatekey=./.ssh/id_rsa

Then I mount it into the container:

"volumeMounts": [
        {"name": "cfg", "readOnly": false, "mountPath": "/home/hcom/.ssh"}
      ]

"volumes": [
      {"name": "cfg", "secret": { "secretName": "hcom-ssh" }}
    ],

What should be id_rsa becomes ssh-privatekey and also the permissions on it are not 600 which ssh needs. Am I doing something wrong here. Please shine some light?

Jan 24 in Kubernetes by Atul
• 5,490 points
34 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

Check the official docs here for a similar use case. Create the secret using:

$ kubectl create secret generic my-secret --from-file=ssh-privatekey=/path/to/.ssh/id_rsa --from-file=ssh-publickey=/path/to/.ssh/id_rsa.pub

Now mount it using this pod config:

{
  "kind": "Pod",
  "apiVersion": "v1",
  "metadata": {
    "name": "secret-test-pod",
    "labels": {
      "name": "secret-test"
    }
  },
  "spec": {
    "volumes": [
      {
        "name": "secret-volume",
        "secret": {
          "secretName": "my-secret"
        }
      }
    ],
    "containers": [
      {
        "name": "ssh-test-container",
        "image": "mySshImage",
        "volumeMounts": [
          {
            "name": "secret-volume",
            "readOnly": true,
            "mountPath": "/etc/secret-volume"
          }
        ]
      }
    ]
  }
}

Kubernetes in itself does not have any way of controlling file permissions for a secret right now. You can check out this if it helps:

answered Jan 24 by ajs3033
• 7,080 points

Related Questions In Kubernetes

0 votes
2 answers
0 votes
1 answer

Command to get the secret key used to login into the dashboard

Hey @Lina, use this command you'll get ...READ MORE

answered Oct 8, 2018 in Kubernetes by Kalgi
• 36,420 points
25 views
0 votes
1 answer
0 votes
3 answers

Error while joining cluster with node

Hi Kalgi after following above steps it ...READ MORE

answered Jan 17 in Others by anonymous
748 views
+3 votes
1 answer
0 votes
1 answer

How to use gravitational teleport in a container/kubernetes environment?

You can use teleport to augment kubernetes ...READ MORE

answered Jun 28, 2018 in Kubernetes by ajs3033
• 7,080 points
202 views
0 votes
1 answer

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.