Skip to content

Instantly share code, notes, and snippets.

@cdoan1
Created July 12, 2019 04:59
Show Gist options
  • Save cdoan1/99adc659234eaf7c561bfd787ee9f07d to your computer and use it in GitHub Desktop.
Save cdoan1/99adc659234eaf7c561bfd787ee9f07d to your computer and use it in GitHub Desktop.
#!/bin/bash
HCURL=${1:-$HCURL}
HCUSER=${2:-$HCUSER}
HCPASS=${3:-$HCPASS}
MCURL=${4:-$MCURL}
MCUSER=${5:-$MCUSER}
MCPASS=${6:-$MCPASS}
# login to managed cluster
cloudctl login -a $MCURL -u $MCUSER -p $MCPASS -n kube-system
MCNAME=$(kubectl config current-context | sed 's/-context//')
kubectl config delete-context $MCNAME
kubectl config get-contexts | grep '*' | awk '{print $2}'| xargs -I % kubectl config rename-context % $MCNAME
kubectl config view --minify=true --context $MCNAME > kubeconfig
sed -i.bak 's/^ certificate-authority:.*/ insecure-skip-tls-verify: true/' kubeconfig
cloudctl logout
# login to hub
cloudctl login -a $HCURL -u $HCUSER -p $HCPASS -n kube-system
cloudctl mc cluster template $MCNAME -n $MCNAME > cluster-import.yaml
cloudctl mc cluster import -f cluster-import.yaml --cluster-kubeconfig kubeconfig
cloudctl logout
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment