Skip to content

Instantly share code, notes, and snippets.

@jflemer
Created March 3, 2023 15:29
Show Gist options
  • Save jflemer/153185cea6bf0aa9b148659c61d602da to your computer and use it in GitHub Desktop.
Save jflemer/153185cea6bf0aa9b148659c61d602da to your computer and use it in GitHub Desktop.
Quick and dirty setup remote access to kubernetes (k8s) cluster with kubectl
#!/bin/bash
# To rapidly setup remote access to a kubernetes cluster, dump the config from
# the master to the local system (e.g. your laptop or workstation)
#
# ssh master kubectl config view --show-managed-fields=true --raw=true | \
# sed "s/127.0.0.1/${CLUSTER}/g" > ~/.kube/config
# Tested against cluster created with k3s version v1.25.6+k3s1 (9176e03c)
if [ -z "$1" ]; then
echo "usage: $(basename $0) cluster-fqdn" >&2
exit 64
fi
CLUSTER="$1"
CONF=~/.kube/config
if [ -e "${CONF}" ]; then
echo "ERROR: ${CONF} already exists!" >&2
exit 1
fi
ssh "root@${CLUSTER}" kubectl config view --show-managed-fields=true --raw=true | \
sed "s/127.0.0.1/${CLUSTER}/g" > "${CONF}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment