-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathkubectl.sh
More file actions
executable file
·27 lines (24 loc) · 865 Bytes
/
kubectl.sh
File metadata and controls
executable file
·27 lines (24 loc) · 865 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/usr/bin/env bash
# Select environment between test, dev or prod
# Usage: source ./kubectl.sh [test|dev|prod]
CTFP_EXECUTE=true
if [ -z "$1" ]; then
echo "Usage: source $0 [test|dev|prod]"
CTFP_EXECUTE=false
fi
if [ "$CTFP_EXECUTE" = true ]; then
CTFP_ENVIRONMENT=$1
echo "Setting up kubectl for environment: $CTFP_ENVIRONMENT"
# Check if the kube-config directory exists, if not create it
if [ ! -d "./kube-config" ]; then
mkdir -p ./kube-config
fi
# Check if the kube-config file exists, if not then fail
if [ -f "./kube-config/kube-config.$CTFP_ENVIRONMENT.yml" ]; then
export KUBECONFIG=${KUBECONFIG:-~/.kube/config}:$(pwd)/kube-config/kube-config.$CTFP_ENVIRONMENT.yml
kubectl config use-context k3s
echo "KUBECONFIG set to k3s"
else
echo "Kube-config file not found!"
fi
fi