Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save v1k0d3n/23e08418f8a32ad6a0da700b06a81b0d to your computer and use it in GitHub Desktop.
Save v1k0d3n/23e08418f8a32ad6a0da700b06a81b0d to your computer and use it in GitHub Desktop.
How to extract kubeconfig and kubeadmin password from OpenShift ClusterDeployment using RHACM
#!/bin/bash
# https://guifreelife.com/blog/2021/08/13/RHACM-Recover-Created-Cluster-Credentials-and-Kubeconfig/
#
# If an OpenShift cluster was created by RHACM this script will extract the
# kubeconfig and the default kubeadmin credentials.
#
# Prereqs:
# - Authenticated to hub cluster
# - Managed cluster name is the sames as the hosting namespace on hub cluster
# read cluster name from CLI
CLUSTER_NAME=${1:-demo}
mkdir -p $CLUSTER_NAME/auth
oc extract -n "$CLUSTER_NAME" \
$(oc get secret -o name -n "$CLUSTER_NAME" \
-l hive.openshift.io/cluster-deployment-name="$CLUSTER_NAME" \
-l hive.openshift.io/secret-type=kubeconfig) \
--to="$CLUSTER_NAME/auth/" \
--confirm
oc extract -n "$CLUSTER_NAME" \
$(oc get secret -o name -n "$CLUSTER_NAME" \
-l hive.openshift.io/cluster-deployment-name="$CLUSTER_NAME" \
-l hive.openshift.io/secret-type=kubeadmincreds ) \
--to="$CLUSTER_NAME/auth/" \
--confirm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment