Created
April 14, 2022 07:05
-
-
Save dennybaa/7c8418e5982946fa6626f7e21083b0d2 to your computer and use it in GitHub Desktop.
~/.kube/config generator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
## ~/.kube/config generator | |
## | |
## - creates ~/.kube/config file with the provided context name | |
## - uses authentication helper which cats token from the path given (used with volume projection) | |
: ${KUBE_CONTEXT:?kube context name is not provided} | |
: ${KUBE_TOKENPATH:?path to Kubernetes token path is not provided} | |
mkdir -p $HOME/.kube/bin | |
# ~/.kube/config | |
cat <<EHD > $HOME/.kube/config | |
apiVersion: v1 | |
clusters: | |
- cluster: | |
insecure-skip-tls-verify: true | |
server: https://kubernetes.default | |
name: default | |
contexts: | |
- context: | |
cluster: default | |
user: user | |
name: $context | |
current-context: $context | |
kind: Config | |
preferences: {} | |
users: | |
- name: user | |
user: | |
exec: | |
command: "./bin/token" | |
apiVersion: "client.authentication.k8s.io/v1beta1" | |
interactiveMode: Never | |
EHD | |
# auth helper | |
cat <<EHD > $HOME/.kube/bin/token | |
{ | |
"apiVersion": "client.authentication.k8s.io/v1beta1", | |
"kind": "ExecCredential", | |
"status": { | |
"token": "$(cat $token_path)" | |
} | |
} | |
chmod 755 $HOME/.kube/bin/token |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment