Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deployments with volumes do not have the option to select a key #116868

Closed
firemanxbr opened this issue Mar 22, 2023 · 5 comments
Closed

Deployments with volumes do not have the option to select a key #116868

firemanxbr opened this issue Mar 22, 2023 · 5 comments
Labels
kind/feature Categorizes issue or PR as related to a new feature. needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one.

Comments

@firemanxbr
Copy link

What would you like to be added?

Problem statement:
Currently, we don't have a way to define a key into a Secret to be used by volumes.

volumes:
    - name: NameOfVolume
      secret:
        secretName: NameOfSecret

Using this approach we should create a separate Secret to be used in a volume. If we add in a Secret with more keys resource will consume all keys.

Why is this needed?

As used in Deployments out of volumes we already have a proper solution:

env:
- name: ENVIRONMENT_VARIABLE
  valueFrom:
    secretKeyRef: 
      name: SecretName
      key: KEY_TO_BE_USED

In that case, will be nice to extend volume API to have:

volumes:
    - name: NameOfVolume
      secret:
        secretName: NameOfSecret
        secretKey: KEY_TO_BE_USED
@firemanxbr firemanxbr added the kind/feature Categorizes issue or PR as related to a new feature. label Mar 22, 2023
@k8s-ci-robot k8s-ci-robot added the needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. label Mar 22, 2023
@k8s-ci-robot
Copy link
Contributor

There are no sig labels on this issue. Please add an appropriate label by using one of the following commands:

  • /sig <group-name>
  • /wg <group-name>
  • /committee <group-name>

Please see the group list for a listing of the SIGs, working groups, and committees available.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added the needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. label Mar 22, 2023
@k8s-ci-robot
Copy link
Contributor

This issue is currently awaiting triage.

If a SIG or subproject determines this is a relevant issue, they will accept it by applying the triage/accepted label and provide further guidance.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@pacoxu
Copy link
Member

pacoxu commented Mar 23, 2023

Why not use subpath?

I created a secret with a key config and mount the secret to the subpath of /root with a path name that can be specified. Does this meet your requirement?

 kubectl create secret generic mysecret --from-file=.kube/config
[root@paco-centos-9 ~]# cat test.yaml
apiVersion: v1
kind: Pod
metadata:
  name: mypod
spec:
  containers:
  - name: mypod
    image: m.daocloud.io/docker.io/library/redis
    volumeMounts:
    - name: foo-config
      mountPath: "/root/"
  volumes:
  - name: foo-config
    secret:
      secretName: mysecret
      items:
      - key: config
        path: config.yaml
[root@paco-centos-9 ~]# kubectl create -f test.yaml
pod/mypod created
[root@paco-centos-9 ~]# kubectl get pod mypod
NAME    READY   STATUS    RESTARTS   AGE
mypod   1/1     Running   0          12s
[root@paco-centos-9 ~]# kubectl exec -it mypod -- ls /root/
config.yaml

@liggitt
Copy link
Member

liggitt commented Mar 24, 2023

projected volumes let you select specific keys of a secret and assign them to specific filepaths

See https://kubernetes.io/docs/concepts/storage/projected-volumes/

...
  volumes:
  - name: my-volume
    projected:
      sources:
      - secret:
          name: my-secret
          items:
            - key: username
              path: my-group/my-username

@liggitt liggitt closed this as completed Mar 24, 2023
@firemanxbr
Copy link
Author

Thank you for guiding me @pacoxu @liggitt!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature Categorizes issue or PR as related to a new feature. needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one.
Projects
None yet
Development

No branches or pull requests

4 participants