Create a kubeconfig file
You can add a cluster to Astra Control Service using a kubeconfig file. Depending on the type of cluster you want to add, you might need to manually create a kubeconfig file for your cluster using specific steps.
Create a kubeconfig file for Amazon EKS clusters
Follow these instructions to create a kubeconfig file and permanent token secret for Amazon EKS clusters. A permanent token secret is required for clusters hosted in EKS.
-
Follow the instructions in the Amazon documentation to generate a kubeconfig file:
-
Create a service account as follows:
-
Create a service account file called
astracontrol-service-account.yaml
.Adjust the service account name as needed. The namespace
kube-system
is required for these steps. If you change the service account name here, you should apply the same changes in the following steps.astracontrol-service-account.yaml
-
-
Apply the service account:
-
Create a
ClusterRoleBinding
file calledastracontrol-clusterrolebinding.yaml
.astracontrol-clusterrolebinding.yaml
-
Apply the cluster role binding:
-
Create a service account token secret file called
astracontrol-secret.yaml
.astracontrol-secret.yaml
-
Apply the token secret:
-
Retrieve the token secret:
-
Replace the
user
section of the AWS EKS kubeconfig file with the token, as shown in the following example:
Create a kubeconfig file for Red Hat OpenShift Service on AWS (ROSA) clusters
Follow these instructions to create a kubeconfig file for Red Hat OpenShift Service on AWS (ROSA) clusters.
-
Log in to the ROSA cluster.
-
Create a service account:
-
Add a cluster role:
-
Using the following example, create a service account secret configuration file:
secret-astra-sa.yaml
-
Create the secret:
-
Edit the service account that you created, and add the Astra Control service account secret name to the
secrets
section: -
List the service account secrets, replacing
<CONTEXT>
with the correct context for your installation:The end of the output should look similar to the following:
"secrets": [ { "name": "astracontrol-service-account-dockercfg-dvfcd"}, { "name": "secret-astracontrol-service-account"} ]
The indices for each element in the
secrets
array begin with 0. In the above example, the index forastracontrol-service-account-dockercfg-dvfcd
would be 0 and the index forsecret-astracontrol-service-account
would be 1. In your output, make note of the index number for the service account secret. You will need this index number in the next step. -
Generate the kubeconfig as follows:
-
Create a
create-kubeconfig.sh
file. ReplaceTOKEN_INDEX
in the beginning of the following script with the correct value.create-kubeconfig.sh
-
Source the commands to apply them to your Kubernetes cluster.
-
-
(Optional) Rename the kubeconfig to a meaningful name for your cluster.
mv kubeconfig-sa YOUR_CLUSTER_NAME_kubeconfig
Create a kubeconfig file for other types of clusters
Follow these instructions to create a limited or expanded role kubeconfig file for Rancher, Upstream Kubernetes, and Red Hat OpenShift clusters.
For clusters that are managed using kubeconfig, you can optionally create a limited permission or expanded permission administrator role for Astra Control Service.
This procedure helps you to create a separate kubeconfig if either of the following scenarios applies to your environment:
-
You want to limit Astra Control permissions on the clusters it manages
-
You use multiple contexts and cannot use the default Astra Control kubeconfig configured during installation or a limited role with a single context won't work in your environment
Ensure that you have the following for the cluster you intend to manage before completing the procedure steps:
-
A supported version of kubectl is installed.
-
kubectl access to the cluster that you intend to add and manage with Astra Control Service
For this procedure, you do not need kubectl access to the cluster that is running Astra Control Service. -
An active kubeconfig for the cluster you intend to manage with cluster admin rights for the active context
-
Create a service account:
-
Create a service account file called
astracontrol-service-account.yaml
.astracontrol-service-account.yaml
-
Apply the service account:
-
-
Create one of the following cluster roles with sufficient permissions for a cluster to be managed by Astra Control:
Limited cluster roleThis role contains the minimum permissions necessary for a cluster to be managed by Astra Control:
-
Create a
ClusterRole
file called, for example,astra-admin-account.yaml
.astra-admin-account.yaml
-
(For OpenShift clusters only) Append the following at the end of the
astra-admin-account.yaml
file: -
Apply the cluster role:
-
-
Create the cluster role binding for the cluster role to the service account:
-
Create a
ClusterRoleBinding
file calledastracontrol-clusterrolebinding.yaml
.astracontrol-clusterrolebinding.yaml
-
Apply the cluster role binding:
-
-
Create and apply the token secret:
-
Create a token secret file called
secret-astracontrol-service-account.yaml
.secret-astracontrol-service-account.yaml
-
Apply the token secret:
-
-
Add the token secret to the service account by adding its name to the
secrets
array (the last line in the following example):apiVersion: v1 imagePullSecrets: - name: astracontrol-service-account-dockercfg-48xhx kind: ServiceAccount metadata: annotations: kubectl.kubernetes.io/last-applied-configuration: | {"apiVersion":"v1","kind":"ServiceAccount","metadata":{"annotations":{},"name":"astracontrol-service-account","namespace":"default"}} creationTimestamp: "2023-06-14T15:25:45Z" name: astracontrol-service-account namespace: default resourceVersion: "2767069" uid: 2ce068c4-810e-4a96-ada3-49cbf9ec3f89 secrets: - name: astracontrol-service-account-dockercfg-48xhx - name: secret-astracontrol-service-account
-
List the service account secrets, replacing
<context>
with the correct context for your installation:The end of the output should look similar to the following:
"secrets": [ { "name": "astracontrol-service-account-dockercfg-48xhx"}, { "name": "secret-astracontrol-service-account"} ]
The indices for each element in the
secrets
array begin with 0. In the above example, the index forastracontrol-service-account-dockercfg-48xhx
would be 0 and the index forsecret-astracontrol-service-account
would be 1. In your output, make note of the index number for the service account secret. You'll need this index number in the next step. -
Generate the kubeconfig as follows:
-
Create a
create-kubeconfig.sh
file. -
Replace
TOKEN_INDEX
in the beginning of the following script with the correct value.create-kubeconfig.sh
# Update these to match your environment. # Replace TOKEN_INDEX with the correct value # from the output in the previous step. If you # didn't change anything else above, don't change # anything else here. SERVICE_ACCOUNT_NAME=astracontrol-service-account NAMESPACE=default NEW_CONTEXT=astracontrol KUBECONFIG_FILE='kubeconfig-sa' CONTEXT=$(kubectl config current-context) SECRET_NAME=$(kubectl get serviceaccount ${SERVICE_ACCOUNT_NAME} \ --context ${CONTEXT} \ --namespace ${NAMESPACE} \ -o jsonpath='{.secrets[TOKEN_INDEX].name}') TOKEN_DATA=$(kubectl get secret ${SECRET_NAME} \ --context ${CONTEXT} \ --namespace ${NAMESPACE} \ -o jsonpath='{.data.token}') TOKEN=$(echo ${TOKEN_DATA} | base64 -d) # Create dedicated kubeconfig # Create a full copy kubectl config view --raw > ${KUBECONFIG_FILE}.full.tmp # Switch working context to correct context kubectl --kubeconfig ${KUBECONFIG_FILE}.full.tmp config use-context ${CONTEXT} # Minify kubectl --kubeconfig ${KUBECONFIG_FILE}.full.tmp \ config view --flatten --minify > ${KUBECONFIG_FILE}.tmp # Rename context kubectl config --kubeconfig ${KUBECONFIG_FILE}.tmp \ rename-context ${CONTEXT} ${NEW_CONTEXT} # Create token user kubectl config --kubeconfig ${KUBECONFIG_FILE}.tmp \ set-credentials ${CONTEXT}-${NAMESPACE}-token-user \ --token ${TOKEN} # Set context to use token user kubectl config --kubeconfig ${KUBECONFIG_FILE}.tmp \ set-context ${NEW_CONTEXT} --user ${CONTEXT}-${NAMESPACE}-token-user # Set context to correct namespace kubectl config --kubeconfig ${KUBECONFIG_FILE}.tmp \ set-context ${NEW_CONTEXT} --namespace ${NAMESPACE} # Flatten/minify kubeconfig kubectl config --kubeconfig ${KUBECONFIG_FILE}.tmp \ view --flatten --minify > ${KUBECONFIG_FILE} # Remove tmp rm ${KUBECONFIG_FILE}.full.tmp rm ${KUBECONFIG_FILE}.tmp
-
Source the commands to apply them to your Kubernetes cluster.
-
-
(Optional) Rename the kubeconfig to a meaningful name for your cluster.
mv kubeconfig-sa YOUR_CLUSTER_NAME_kubeconfig