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, 2019 in Kubernetes by ffdfd
• 5,550 points
4,278 views

1 answer to this question.

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, 2019 by ajs3033
• 7,300 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
• 52,360 points
538 views
+1 vote
1 answer
0 votes
3 answers

Error while joining cluster with node

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

answered Jan 17, 2019 in Others by anonymous
14,523 views
+4 votes
1 answer

Installing Web UI (Dashboard):kubernetes-dashboard on main Ubuntu 16.04.6 LTS (Xenial Xerus) server

Follow these steps: $ kubeadm reset $ kubeadm init ...READ MORE

answered Apr 12, 2019 in Kubernetes by Kalgi
• 52,360 points

reshown Apr 12, 2019 by Kalgi 5,976 views
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,300 points
2,216 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP