2

I am trying to create a deployment which is deployed on K8S instance on which it does migration of services. This needs kubeconfig as part of the code right now. We do not have access to create service accounts. We also have kubectl binary inside the container which does some operations. Whats the best way to take kubeconfig as input ?

Tech_Lover
  • 21
  • 1
  • 3

1 Answers1

2

Volume mount the kubeconfig that is in a Secret, and then point the KUBECONFIG environment variable at the path in which the Secret is mounted

kind: Secret
metadata:
  name: my-k-config
stringData:
  my-kubeconfig: |
     clusters:
     - ... etc etc
---
kind: Pod
spec:
  containers:
  - name: sample
    command: ["kubectl", "get", "namespaces"]
    env:
    - name: KUBECONFIG
      value: /k-cfg/my-kubeconfig
    volumeMounts:
    - name: k-config
      mountPath: /k-cfg
  volumes:
  - name: k-config
    secret:
      secretName: my-k-config
mdaniel
  • 2,338
  • 1
  • 8
  • 13