Last active
April 19, 2024 15:09
-
-
Save dlbewley/f57eb2bb5b69d2db0df7b171329a68cc to your computer and use it in GitHub Desktop.
How to extract kubeconfig and kubeadmin password from OpenShift ClusterDeployment using RHACM
This file contains hidden or 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 | |
# 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