Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions scripts/cluster-creation/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Instructions to create k8s clusters

## On-Prem K8s Cluster

on-prem k8s cluster can be created on any VM or physical machine using kind.

```
bash onprem-k8s.sh --cluster-name <name-of-the-cluster>
```

## AKS-Engine cluster

aks-engine is unmanaged cluster in azure and you can use below command to create the cluster in azure.

```

# Either you can reuse existing service principal or create one with below instructions
subscriptionId="<subscription id>"
az account set -s ${subscriptionId}
sp=$(az ad sp create-for-rbac --role="Contributor" --scopes="/subscriptions/${subscriptionId}")
# get the appId (i.e. clientid) and password (i.e. clientSecret)
echo $sp

clientId=$(echo $sp | jq '.appId')
clientSecret=$(echo $sp | jq '.password')

# create the aks-engine
bash aks-engine.sh --subscription-id "<subscriptionId>" --client-id "<clientId>" --client-secret "<clientSecret>" --dns-prefix "<clusterDnsPrefix>" --location "<location>"
```

## ARO v4 Cluster

Azure Redhat Openshift v4 cluster can be created with below command.

> Note: Because of the cleanup policy on internal subscriptions, cluster creation can fail if you dont change cleanup service to none on the subnets of aro vnet before creation.
```
bash aro-v4.sh --subscription-id "<subscriptionId>" --resource-group "<rgName>" --cluster-name "<clusterName>" --location "<location>"
```
## Azure Arc K8s cluster

you can connect on-prem k8s cluster or unmanaged k8s cluster such as aks-engine to azure through azure arc.

```
bash arc-k8s-cluster.sh --subscription-id "<subId>" --resource-group "<rgName>" --cluster-name "<clusterName>" --location "<location>" --kube-context "<contextofexistingcluster>"
```
163 changes: 163 additions & 0 deletions scripts/cluster-creation/aks-engine.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
#!/bin/bash
set -e
TEMP_DIR=temp-$RANDOM
DEFAULT_ONPREM_K8S_CLUSTER="aks-engine-k8s-test"
AKS_ENGINE_VERSION="v0.54.0"

download-aks-engine()
{
sudo curl -LO https://github.com/Azure/aks-engine/releases/download/${AKS_ENGINE_VERSION}/aks-engine-v0.54.0-linux-amd64.tar.gz
sudo tar -xvf aks-engine-${AKS_ENGINE_VERSION}-linux-amd64.tar.gz
sudo mv aks-engine-${AKS_ENGINE_VERSION}-linux-amd64 aks-engine
sudo mv -f aks-engine/aks-engine /usr/local/bin
}


usage()
{
local basename=`basename $0`
echo
echo "create aks-engine cluster:"
echo "$basename deploy --subscription-id <subscriptionId> --client-id <clientId> --client-secret <clientSecret> --dns-prefix <dns-prefix> --location <location>"
}

parse_args()
{

if [ $# -le 1 ]
then
usage
exit 1
fi

# Transform long options to short ones
for arg in "$@"; do
shift
case "$arg" in
"--subscription-id") set -- "$@" "-s" ;;
"--client-id") set -- "$@" "-c" ;;
"--client-secret") set -- "$@" "-w" ;;
"--dns-prefix") set -- "$@" "-d" ;;
"--location") set -- "$@" "-l" ;;
"--"*) usage ;;
*) set -- "$@" "$arg"
esac
done

local OPTIND opt

while getopts 'hs:c:w:d:l:' opt; do
case "$opt" in
h)
usage
;;

s)
subscriptionId="$OPTARG"
echo "subscriptionId is $OPTARG"
;;

c)
clientId="$OPTARG"
echo "clientId is $OPTARG"
;;

w)
clientSecret="$OPTARG"
echo "clientSecret is $OPTARG"
;;

d)
dnsPrefix="$OPTARG"
echo "dnsPrefix is $OPTARG"
;;

l)
location="$OPTARG"
echo "location is $OPTARG"
;;

?)
usage
exit 1
;;
esac
done
shift "$(($OPTIND -1))"


}
create_cluster()
{

sudo touch kubernetes.json
sudo chmod 777 kubernetes.json
# For docker runtime, remove kubernetesConfig block
cat >> kubernetes.json <<EOL
{
"apiVersion": "vlabs",
"properties": {
"orchestratorProfile": {
"orchestratorType": "Kubernetes",
"orchestratorRelease": "1.16",
"kubernetesConfig": {
"containerRuntime": "containerd"
}
},
"masterProfile": {
"count": 1,
"dnsPrefix": "",
"vmSize": "Standard_D2_v3"
},
"agentPoolProfiles": [
{
"name": "agentpool1",
"count": 2,
"vmSize": "Standard_D2_v3"
}
],
"linuxProfile": {
"adminUsername": "azureuser",
"ssh": {
"publicKeys": [
{
"keyData": ""
}
]
}
},
"servicePrincipalProfile": {
"clientId": "",
"secret": ""
}
}
}
EOL

echo "deploying aks-engine cluster ..."
sudo aks-engine deploy --subscription-id ${subscriptionId} --client-id ${clientId} --client-secret ${clientSecret} --dns-prefix ${dnsPrefix} --location ${location} --api-model kubernetes.json
echo "deploying of aks-engine cluster completed."

}



echo "creating aks-engine k8s cluster ..."
echo "AKS-ENGINE version: ${AKS_ENGINE_VERSION}"
cd ~
echo "creating temp directory":$TEMP_DIR
sudo mkdir $TEMP_DIR && cd $TEMP_DIR

echo "validate args"
parse_args $@

echo "download aks-engine"
download-aks-engine

echo "creating cluster: ${ClusterName}"
create_cluster
echo "creating aks-engine cluster completed."

echo "changing file permissions to access the kubeconfig"
sudo chmod -R 777 ~/${TEMP_DIR}/_output
echo "kubeconfig of this cluster should be under ~/${TEMP_DIR}/_output/${dnsPrefix}/kubeconfig"
Loading