Skip to content

Commit

Permalink
Add Kubernetes cluster deployment templates and scripts
Browse files Browse the repository at this point in the history
Signed-off-by: Marius Oprin <[email protected]>
  • Loading branch information
oprinmarius committed Jan 10, 2020
1 parent 723e350 commit 8d89444
Show file tree
Hide file tree
Showing 3 changed files with 163 additions and 0 deletions.
89 changes: 89 additions & 0 deletions kubernetes/acc-k8s-cluster.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
{
"apiVersion": "vlabs",
"properties": {
"orchestratorProfile": {
"orchestratorType": "Kubernetes",
"kubernetesConfig": {
"addons": [
{
"name": "tiller",
"enabled" : true
},
{
"name": "cluster-autoscaler",
"enabled": true,
"pools": [
{
"name": "agentsbionic",
"config": {
"min-nodes": "1",
"max-nodes": "5"
}
},
{
"name": "agentsxenial",
"config": {
"min-nodes": "1",
"max-nodes": "5"
}
}
],
"config": {
"scan-interval": "1m"
}
}
]
}
},
"masterProfile": {
"count": 1,
"vmSize": "Standard_D2s_v3",
"vnetSubnetId": "${VNET_SUBNET_ID}",
"dnsPrefix": "${DNS_PREFIX}",
"firstConsecutiveStaticIP": "${FIRST_CONSECUTIVE_IP}"
},
"agentPoolProfiles": [
{
"name": "agentsbionic",
"count": 2,
"availabilityProfile": "VirtualMachineScaleSets",
"distro": "aks-ubuntu-18.04",
"vmSize": "Standard_DC2s",
"vnetSubnetId": "${VNET_SUBNET_ID}",
"storageProfile": "ManagedDisks"
},
{
"name": "agentsxenial",
"count": 2,
"availabilityProfile": "VirtualMachineScaleSets",
"distro": "acc-16.04",
"vmSize": "Standard_DC2s",
"vnetSubnetId": "${VNET_SUBNET_ID}",
"storageProfile": "ManagedDisks"
}
],
"linuxProfile": {
"adminUsername": "azureuser",
"ssh": {
"publicKeys": [
{
"keyData": "${SSH_PUBLIC_KEY}"
}
]
}
},
"extensionProfiles": [
{
"name": "prometheus-grafana-k8s",
"version": "v1"
}
],
"servicePrincipalProfile": {
"clientId": "f04638d3-aa98-4981-8c0e-efdd2ae6a035",
"keyvaultSecretRef": {
"vaultID": "/subscriptions/c4fdda6e-bfbd-4b8e-9703-037b3a45bf37/resourceGroups/osct-test-infra/providers/Microsoft.KeyVault/vaults/ostc-test-kv",
"secretName": "sp-pwd-ostclab"
}
}
}
}
18 changes: 18 additions & 0 deletions kubernetes/admin-user.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: admin-user
namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: admin-user
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
subjects:
- kind: ServiceAccount
name: admin-user
namespace: kube-system
56 changes: 56 additions & 0 deletions kubernetes/deploy-k8s.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env bash

# Copyright (c) Open Enclave SDK contributors.
# Licensed under the MIT License.

set -o errexit

if [[ -z $SUBSCRIPTION_ID ]]; then echo "ERROR: Env variable SUBSCRIPTION_ID is not set"; exit 1; fi
if [[ -z $SERVICE_PRINCIPAL_ID ]]; then echo "ERROR: Env variable SERVICE_PRINCIPAL_ID is not set"; exit 1; fi
if [[ -z $SERVICE_PRINCIPAL_PASSWORD ]]; then echo "ERROR: Env variable SERVICE_PRINCIPAL_PASSWORD is not set"; exit 1; fi
if [[ -z $TENANT_ID ]]; then echo "ERROR: Env variable TENANT_ID is not set"; exit 1; fi
if [[ -z $REGION ]]; then echo "ERROR: Env variable REGION is not set"; exit 1; fi
if [[ -z $RESOURCE_GROUP ]]; then echo "ERROR: Env variable RESOURCE_GROUP is not set"; exit 1; fi
if [[ -z $VNET_SUBNET_ID ]]; then echo "ERROR: Env variable VNET_SUBNET_ID is not set"; exit 1; fi
if [[ -z $DNS_PREFIX ]]; then echo "ERROR: Env variable DNS_PREFIX is not set"; exit 1; fi

#
# Create the Azure ACC Kubernetes cluster via aks-engine
#
az login --service-principal -u "${SERVICE_PRINCIPAL_ID}" -p "${SERVICE_PRINCIPAL_PASSWORD}" --tenant "${TENANT_ID}" --output table
az account set --subscription "${SUBSCRIPTION_ID}"

KEY=$(az keyvault secret show --vault-name "oe-ci-test-kv" --name "id-rsa-oe-test-pub" | jq -r .value | base64 -d)
PASSWORD=$(az keyvault secret show --vault-name "oe-ci-test-kv" --name "windows-pwd" | jq -r .value)

export WINDOWS_ADMIN_PASSWORD="$PASSWORD"
export SSH_PUBLIC_KEY="$KEY"

TEMPLATE="acc-k8s-cluster.json"


DIR=$(dirname "$0")
cd "$DIR"
eval "cat << EOF
$(cat "$TEMPLATE")
EOF
" > aks-engine-template.json
aks-engine generate aks-engine-template.json
RG_EXISTS=$(az group exists --name "$RESOURCE_GROUP")
if [[ "$RG_EXISTS" = "false" ]]; then
az group create --name "$RESOURCE_GROUP" --location "$REGION" --output table
fi
az group deployment create --name acc-k8s \
--resource-group ${RESOURCE_GROUP} \
--template-file _output/${DNS_PREFIX}/azuredeploy.json\
--parameters @_output/${DNS_PREFIX}/azuredeploy.parameters.json \
--output table

export KUBECONFIG=_output/${DNS_PREFIX}/kubeconfig/kubeconfig.${REGION}.json
kubectl get nodes
kubectl apply -f "admin-user.yml"

az keyvault secret set --vault-name "oe-ci-test-kv" --name "kubeconfig-${DNS_PREFIX}-${REGION}" --file ${KUBECONFIG} --description "${DNS_PREFIX}.${REGION}.cloudapp.azure.com Kubeconfig"

echo "KUBECONFIG file successfully uploaded to oe-ci-test-kv keyvault"
exit 0

0 comments on commit 8d89444

Please sign in to comment.