Skip to content

Commit

Permalink
update scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
britaniar committed Mar 19, 2024
1 parent 390fc26 commit 99f5692
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 30 deletions.
29 changes: 10 additions & 19 deletions hack/setup/README.md → hack/Azure/setup/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,15 @@ This how-to guide discusses how to create a fleet, specifically:
> * `cd fleet`
## Create a hub cluster from an AKS Cluster
> Note
>
> Make sure you have already created an AKS cluster and have gotten its credentials.
> Instructions to create an AKS cluster can be found [here](https://learn.microsoft.com/en-us/azure/aks/learn/quick-kubernetes-deploy-cli).
>
For your convenience, Fleet provides a script that can automate the process of creating a hub cluster. To use script,
run the commands bellow:
```sh
# Replace the value of HUB_CLUSTER_CONTEXT with the name of the kubeconfig context you use for
# accessing your hub cluster.
export HUB_CLUSTER_CONTEXT=<YOUR-HUB-CLUSTER-CONTEXT>
# Replace the value of HUB_CLUSTER_ADDRESS with the address of your hub cluster API server located in the kubeconfig file.
export HUB_CLUSTER_ADDRESS=<YOUR-HUB-CLUSTER-ADDRESS>
# Replace the value of <AZURE-SUBSCRIPTION-ID> with your Azure subscription ID.
export SUB=<AZURE-SUBSCRIPTION-ID>

# Run the script.
chmod +x hack/setup/createHubCluster.sh
./hack/setup/createHubCluster.sh
# Run the script. Be sure to replace the values of <RESOURCE-GROUP-NAME>, <LOCATION>, and <HUB-CLUSTER-NAME> with those of your own.
chmod +x hack/Azure/setup/createHubCluster.sh
./hack/Azure/setup/createHubCluster.sh <RESOURCE-GROUP-NAME> <LOCATION> <HUB-CLUSTER-NAME>
```

It may take a few minutes for the script to finish running. Once it is completed, verify that the `hub-agent` has been installed:
Expand Down Expand Up @@ -91,12 +82,12 @@ A cluster can join in a hub cluster if:
For your convenience, Fleet provides a script that can automate the process of joining a cluster
onto a hub cluster. To use the script, run the commands below after creating needed AKS clusters:
```sh
# Pass in a list of cluster names (separated by a space) as arguments to the script that you would like to
# Pass in the hub cluster name and a list of cluster names (separated by a space) as arguments to the script that you would like to
# join the fleet as member clusters. Their context will be used to access the cluster.
# Ex.: ./hack/setup/joinMC.sh member member2 member3 member4
# Ex.: ./hack/setup/joinMC.sh test-hub member member2 member3
# Run the script.
chmod +x hack/setup/joinMC.sh
./hack/setup/joinMC.sh <MEMBER-CLUSTER-NAME-1> <MEMBER-CLUSTER-NAME-2>
chmod +x hack/Azure/setup/joinMC.sh
./hack/Azure/setup/joinMC.sh <HUB-CLUSTER-NAME> <MEMBER-CLUSTER-NAME-1> <MEMBER-CLUSTER-NAME-2> <MEMBER-CLUSTER-NAME-3> <MEMBER-CLUSTER-NAME-4>
```
It may take a few minutes for the script to finish running. Once it is completed, verify
Expand All @@ -109,7 +100,7 @@ kubectl get membercluster $MEMBER_CLUSTER
If you see that the cluster is still in an unknown state, it might be that the member cluster
is still connecting to the hub cluster. Should this state persist for a prolonged
period, refer to the [Troubleshooting Guide](../../docs/troubleshooting/README.md) for
period, refer to the [Troubleshooting Guide](../../../docs/troubleshooting/README.md) for
more information.
## Adding labels to a member cluster
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
# This script creates a Hub CLuster from an AKS Cluster (AKS Cluster and Container Registry must be created beforehand).

export RESOURCE_GROUP=$1
export LOCATION=$2
export HUB_CLUSTER=$3

az account set -s ${SUB}
az group create --name $RESOURCE_GROUP --location $LOCATION
az aks create --resource-group $RESOURCE_GROUP --name $HUB_CLUSTER --node-count 2
az aks get-credentials --resource-group $RESOURCE_GROUP --name $HUB_CLUSTER

export HUB_CLUSTER_CONTEXT=$(kubectl config view -o jsonpath="{.contexts[?(@.context.cluster==\"$HUB_CLUSTER\")].name}")
export HUB_CLUSTER_ADDRESS=$(kubectl config view -o jsonpath="{.clusters[?(@.name==\"$HUB_CLUSTER\")].cluster.server}")


kubectl config use-context $HUB_CLUSTER_CONTEXT

# Build the hub agent image
# Retrieve the hub agent image
echo "Retrieving hub-agent image..."
export REGISTRY="${REGISTRY:-mcr.microsoft.com/aks/fleet}"
export TAG="${TAG:-$(curl "https://api.github.com/repos/Azure/fleet/tags" | jq -r '.[0].name')}"
export REGISTRY="mcr.microsoft.com/aks/fleet"
export TAG=$(curl "https://api.github.com/repos/Azure/fleet/tags" | jq -r '.[0].name')
export OUTPUT_TYPE="${OUTPUT_TYPE:-type=docker}"


Expand Down
18 changes: 10 additions & 8 deletions hack/setup/joinMC.sh → hack/Azure/setup/joinMC.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
# CAN ONLY BE RUN AFTER CREATING NEEDED AKS CLUSTERS AND HUB CLUSTER. This script creates member clusters from
# AKS Cluster's and joins them onto the hub cluster.

for MC in "$@"; do
export HUB_CLUSTER=$1
export HUB_CLUSTER_CONTEXT=$(kubectl config view -o jsonpath="{.contexts[?(@.context.cluster==\"$HUB_CLUSTER\")].name}")
export HUB_CLUSTER_ADDRESS=$(kubectl config view -o jsonpath="{.clusters[?(@.name==\"$HUB_CLUSTER\")].cluster.server}")

for MC in "${@:2}"; do

# Note that Fleet will recognize your cluster with this name once it joins.
export MEMBER_CLUSTER=${MC}
export MEMBER_CLUSTER_CONTEXT=${MC}

export SERVICE_ACCOUNT="$MEMBER_CLUSTER-hub-cluster-access"

echo "Switching into hub cluster context..."
#echo "Switching into hub cluster context..."
kubectl config use-context $HUB_CLUSTER_CONTEXT
# The service account can, in theory, be created in any namespace; for simplicity reasons,
# here you will use the namespace reserved by Fleet installation, `fleet-system`.
Expand Down Expand Up @@ -47,10 +52,6 @@ spec:
heartbeatPeriodSeconds: 60
EOF

# # Clone the Fleet repository from GitHub (If not done so already and go into directory).
# git clone https://github.com/Azure/fleet.git
# cd fleet

# # Install the member agent helm chart on the member cluster.

# The variables below uses the Fleet images kept in the Microsoft Container Registry (MCR),
Expand All @@ -59,9 +60,10 @@ EOF
# You can, however, build the Fleet images of your own; see the repository README for
# more information.
echo "Retrieving image..."
export REGISTRY="${REGISTRY:-mcr.microsoft.com/aks/fleet}"
export REGISTRY="mcr.microsoft.com/aks/fleet"
export FLEET_VERSION="${FLEET_VERSION:-$(curl "https://api.github.com/repos/Azure/fleet/tags" | jq -r '.[0].name')}"
export MEMBER_AGENT_IMAGE="${MEMBER_AGENT_NAME:-member-agent}"
export MEMBER_AGENT_IMAGE="member-agent"
export REFRESH_TOKEN_IMAGE="${REFRESH_TOKEN_NAME:-refresh-token}"
export OUTPUT_TYPE="${OUTPUT_TYPE:-type=docker}"

echo "Switching to member cluster context.."
Expand Down

0 comments on commit 99f5692

Please sign in to comment.