Last active
June 27, 2017 14:43
-
-
Save mattymo/1672406c9db1d851b0b8df845c3c2f3b to your computer and use it in GitHub Desktop.
Federation kubeconfig scripts
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/bash -xe | |
OLD_CLUSTERNAME="local" | |
OLD_CONTEXT="kubelet-cluster.second" | |
OLD_USER="kubelet" | |
LOADBALANCER="https://fed-loadbalancer-childcluster.kube-system" | |
NEW_CLUSTERNAME="childcluster" | |
NEW_CONTEXT="childcluster" | |
NEW_USER="kubelet-childcluster" | |
KUBECONFIG="kubeconfig-child.yaml" | |
export KUBECONFIG | |
JYPARSER="docker run -i --rm jlordiales/jyparser" | |
TMP_KC=$(mktemp /tmp/kubeconfig.XXX) | |
# Update cluster name and server | |
cat $KUBECONFIG | $JYPARSER set ".clusters[0].name" \"${NEW_CLUSTERNAME}\" > $TMP_KC | |
mv $TMP_KC $KUBECONFIG | |
kubectl config set-cluster "$NEW_CLUSTERNAME" --server="${LOADBALANCER}" --insecure-skip-tls-verify=true | |
# Set user name | |
cat $KUBECONFIG | $JYPARSER set ".users[0].name" \"kubelet-childcluster\" > $TMP_KC | |
mv $TMP_KC $KUBECONFIG | |
# Create new context and delete old one | |
kubectl config set-context "$NEW_CONTEXT" --cluster="$NEW_CLUSTERNAME" --user="$NEW_USER" | |
kubectl config use-context "$NEW_CONTEXT" | |
kubectl config delete-context "$OLD_CONTEXT" || echo "Old context was already deleted" |
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/bash -xe | |
OLD_CLUSTERNAME="local" | |
OLD_CONTEXT="kubelet-cluster.local" | |
OLD_USER="kubelet" | |
NEW_CLUSTERNAME="hostcluster" | |
NEW_CONTEXT="hostcluster" | |
NEW_USER="kubelet-hostcluster" | |
KUBECONFIG="kubeconfig-host.yaml" | |
DEFAULT_CONTEXT="federation" | |
export KUBECONFIG | |
JYPARSER="docker run -i --rm jlordiales/jyparser" | |
TMP_KC=$(mktemp /tmp/kubeconfig.XXX) | |
# Update cluster name and server | |
cat "${KUBECONFIG}" | $JYPARSER set ".clusters[1].name" \"${NEW_CLUSTERNAME}\" > $TMP_KC | |
mv "${TMP_KC}" "${KUBECONFIG}" | |
kubectl config set-cluster "$NEW_CLUSTERNAME" --server="https://kubernetes.default" | |
# Set user name | |
cat $KUBECONFIG | $JYPARSER set ".users[1].name" \"${NEW_USER}\" > $TMP_KC | |
mv $TMP_KC $KUBECONFIG | |
# Create new context and delete old one | |
kubectl config set-context "${NEW_CONTEXT}" --cluster="${NEW_CLUSTERNAME}" --user="${NEW_USER}" | |
kubectl config delete-context "${OLD_CONTEXT}" || echo "Old context was already deleted" | |
kubectl config use-context "${DEFAULT_CONTEXT}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment