k8s/helm/apps/sudoscientist-go-backend/install.sh

34 lines
1,022 B
Bash
Raw Normal View History

2022-12-31 21:05:31 +00:00
#!/bin/bash
NAMESPACE=sudoscientist
VAULT_AUTH_NAMESPACE="k8s-teapot"
kubectl create ns sudoscientist
kubectl create serviceaccount -n ${NAMESPACE} sudoscientist
HOST_IP=$(ip addr show eth0 | grep -Po 'inet \K[\d.]+')
TOKEN="$(kubectl get secret serviceaccounttoken -n sudoscientist -o go-template='{{ .data.token }}' | base64 -d)"
cat << EOH > sudoscientist.hcl
path "kv/data/sudoscientist/go-backend" {
capabilities = ["read"]
}
EOH
vault policy write sudoscientist sudoscientist.hcl
rm sudoscientist.hcl
vault write auth/${VAULT_AUTH_NAMESPACE}/role/sudoscientist \
bound_service_account_names=sudoscientist \
bound_service_account_namespaces=sudoscientist \
policies=sudoscientist \
ttl=24h
vault write auth/${VAULT_AUTH_NAMESPACE}/login role=sudoscientist jwt=${TOKEN} iss=https://${HOST_IP}:6443
kubectl apply -n ${NAMESPACE} -f external-secrets.yaml
helm upgrade --install \
sudoscientist \
${HOME}/charts/sudoscientist-go-backend \
-f values.yaml \
-n ${NAMESPACE} \
--cleanup-on-fail