Forked from dlbewley/extract-kubeconfig-acm-created-cluster.sh
Created
April 11, 2024 15:59
-
-
Save v1k0d3n/23e08418f8a32ad6a0da700b06a81b0d to your computer and use it in GitHub Desktop.
How to extract kubeconfig and kubeadmin password from OpenShift ClusterDeployment using RHACM
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 | |
# 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