Creating ssh secrets key file in kubernetes

前端 未结 2 582
星月不相逢
星月不相逢 2021-02-04 14:44

If i create a secret from an id_rsa file using kubectl as:

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

A

2条回答
  •  情话喂你
    2021-02-04 15:08

    Since kubernetes-1.4 things got simpler. Here's my take how to improve the official Kubernetes howto.

    To create the secret, use:

    kubectl create secret generic ssh-keys --from-file=id_rsa=/path/to/.ssh/id_rsa --from-file=id_rsa.pub=/path/to/.ssh/id_rsa.pub
    

    To mount the secret in your containers, use the following Pod config:

    apiVersion: v1
    kind: Pod
    metadata:
      name: secret-test-pod
      labels:
        name: secret-test
    spec:
      volumes:
      - name: ssh-keys-v
        secret:
          secretName: ssh-keys
          defaultMode: 0600 
      containers:
      - name: ssh-test-container
        image: mySshImage
        volumeMounts:
        - name: ssh-keys-v
          readOnly: true
          # container will see /root/.ssh/id_rsa as usual:
          mountPath: "/root/.ssh"
    

    Also nitpick: the id_rsa.pub is hardly ever used, I wouldn't bother to secretize it until required.

提交回复
热议问题