Initial commit.
This commit is contained in:
commit
840bd2e12a
10 changed files with 322 additions and 0 deletions
75
bin/create-vcluster.sh
Executable file
75
bin/create-vcluster.sh
Executable file
|
@ -0,0 +1,75 @@
|
|||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
# VARIABLES
|
||||
# Relative PATH to the workdir from the script directory
|
||||
WORK_DIR_RELPATH="../vcluster"
|
||||
|
||||
# Compute WORKDIR
|
||||
SCRIPT="$(readlink -f "$0")"
|
||||
SCRIPT_DIR="$(dirname "$SCRIPT")"
|
||||
WORK_DIR="$(readlink -f "$SCRIPT_DIR/$WORK_DIR_RELPATH")"
|
||||
|
||||
# Update the PATH to add the arkade bin directory
|
||||
# Add the arkade binary directory to the path if missing
|
||||
case ":${PATH}:" in
|
||||
*:"${HOME}/.arkade/bin":*) ;;
|
||||
*) export PATH="${PATH}:${HOME}/.arkade/bin" ;;
|
||||
esac
|
||||
|
||||
# Go to the working directory
|
||||
cd "$WORK_DIR" || exit 1
|
||||
|
||||
echo "=> Creating or updating the vcluster"
|
||||
vcluster create my-vcluster --namespace my-vcluster --upgrade --connect=false \
|
||||
--values vcluster.yaml
|
||||
|
||||
echo "=> Adding a traefik ingress route tcp to the vcluster api"
|
||||
kubectl apply -f ingress_route_tcp.yaml
|
||||
|
||||
echo "=> Exporting vcluster kubeconfig"
|
||||
tries="0"
|
||||
while true; do
|
||||
if kubectl get -n my-vcluster secret/my-vcluster-kubeconfig >/dev/null 2>&1; then
|
||||
# Dump the kubeconfig if available
|
||||
kubectl get -n my-vcluster secret/my-vcluster-kubeconfig \
|
||||
--template="{{.data.config}}" | base64 -d > ~/.kube/my-vcluster-config
|
||||
echo "KubeConfig dumped to '~/.kube/my-vcluster-config'"
|
||||
break
|
||||
fi
|
||||
tries="$((tries + 1))"
|
||||
echo "KubeConfig not avaliable after attempt '$tries'"
|
||||
if [ "$tries" -lt "10" ]; then
|
||||
sleep 5
|
||||
else
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
if [ "$tries" -eq "10" ]; then
|
||||
echo "=> Failed to get the vcluster kubeconfig, try again"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cat <<EOF
|
||||
=> NOTE
|
||||
Overwrite the KUBECONFIG variable to access the vcluster with 'kubectl':
|
||||
|
||||
KUBECONFIG=~/.kube/my-vcluster-config kubectl
|
||||
|
||||
You can define the following 'vkubectl' alias to make it easier:
|
||||
|
||||
alias vkubectl="KUBECONFIG=~/.kube/my-vcluster-config kubectl"
|
||||
|
||||
Or you can merge it with the one on the KUBECONFIG variable and use 'kubectx' or
|
||||
a similar tool to change the context (for our vcluster the context will be
|
||||
'my-vcluster_k3d-argocd').
|
||||
|
||||
If your KUBECONFIG variable is defined and only has the path to a single file
|
||||
you can merge it with the vcluster config running the following:
|
||||
|
||||
KUBECONFIG="\$KUBECONFIG:~/.kube/my-vcluster-config" \\
|
||||
kubectl config view --flatten > "\$KUBECONFIG.new";
|
||||
mv "\$KUBECONFIG.new" "\$KUBECONFIG"
|
||||
EOF
|
Loading…
Add table
Add a link
Reference in a new issue