Merge pull request #123 from stazdx/aks-terraform

Running it in (Azure Kubernetes Service) AKS by using Terraform, Azure CLI, Kompose & Kubectl
This commit is contained in:
Budi Utomo
2018-10-11 08:18:00 +02:00
committed by GitHub
23 changed files with 758 additions and 0 deletions

80
aks-terraform/README.md Normal file
View File

@@ -0,0 +1,80 @@
# Kubernetes & Azure (AKS, Terraform, Kompose, Kubectl, Azure CLI)
- Azure CLI configuration
- Infrastructure as code for Azure
- Generating Kubernetes configuration files with Kompose (Services, Deployments, Pods & Persistent volumes)
- Terraform with Azure Provider
- Kubectl configuration
## Setting up Azure CLI
- Install Azure CLI -> https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest
- Execute ```sh $ az login ``` and authenticate with your Azure account
- Execute ```sh $ az account show --query "{subscriptionId:id, tenantId:tenantId" ``` . Then copy subscriptionId and tenantId
- Execute ```sh $ az account set --subscription="${SUBSCRIPTION_ID}" ``` . Replace ${SUBSCRIPTION_ID} for your subscriptionId copied
## Create infrastucture in Azure (AKS Service with node master)
Terraform version >= v0.11.7
- Install Terraform -> https://www.terraform.io/downloads.html
- Edit vars with Azure Account values in ```sh terraform.tfvars ```
- After that:
```sh
$ terraform init
$ terraform plan
$ terraform apply
```
## Setting up Kubectl with Azure account
- For apply Kubernetes files:
First configurate azure-cli with Azure account and install kubernetes tools with az:
```sh
$ az aks install-cli
```
Then log in in to the Azure Container Registry (if you're using it, but dockerhub or other):
```sh
$ az acr login
```
After that, connect to cluster with Kubectl:
```sh
$ az aks get-credentials --resource-group docker-android --name k8s-docker-android
```
## Generate Kube files with Kompose
- Install Kompose -> https://github.com/kubernetes/kompose
Kompose version: >= 1.1.0
- For convert to Kompose:
```sh
$ cd kompose
$ kompose convert -f ../kompose.yml
```
## Execute Kube files
- First create Persistent Volume Claims, then Services; finally Deployments files. For example:
```sh
$ cd kompose
$ kubectl create -f nexus-7.1.1-claim0-persistentvolumeclaim.yaml
$ kubectl create -f nexus-7.1.1-claim1-persistentvolumeclaim.yaml
$ kubectl create -f nexus-7.1.1-service.yaml
$ kubectl create -f nexus-7.1.1-deployment.yaml
```
## Running with custom K8s files
(To Do)

114
aks-terraform/kompose.yml Executable file
View File

@@ -0,0 +1,114 @@
# Note: It requires docker-compose 1.13.0
#
# Usage: docker-compose up -d
version: "3"
services:
# Selenium hub
selenium_hub:
image: selenium/hub:3.14.0-curium
ports:
- 4444:4444
# There is a bug for using appium. Issue: https://github.com/butomo1989/docker-android/issues/73
# Real devices
#real_device:
# image: butomo1989/docker-android-real-device
# privileged: true
# depends_on:
# - selenium_hub
# ports:
# - 6080:6080
# volumes:
# - ./video-real-device:/tmp/video
# - /dev/bus/usb:/dev/bus/usb
# - ~/.android:/root/.android
# environment:
# - CONNECT_TO_GRID=true
# - APPIUM=true
# - SELENIUM_HOST=selenium_hub
# - AUTO_RECORD=true
# - BROWSER_NAME=chrome
# Using Appium Docker Android
real_device:
image: appium/appium
depends_on:
- selenium_hub
network_mode: "service:selenium_hub"
privileged: true
volumes:
- /dev/bus/usb:/dev/bus/usb
- ~/.android:/root/.android
- ../example/sample_apk:/root/tmp
environment:
- CONNECT_TO_GRID=true
- SELENIUM_HOST=selenium_hub
# Enable it for msite testing
#- BROWSER_NAME=chrome
# Docker-Android for Android application testing
nexus_7.1.1:
image: butomo1989/docker-android-x86-7.1.1
privileged: true
# Increase scale number if needed
#scale: 1
depends_on:
- selenium_hub
- real_device
ports:
- 6080
# Change path of apk that you want to test. I use sample_apk that I provide in folder "example"
volumes:
- ../example/sample_apk:/root/tmp/sample_apk
- ../video-nexus_7.1.1:/tmp/video
environment:
- DEVICE=Nexus 5
- CONNECT_TO_GRID=true
- APPIUM=true
- SELENIUM_HOST=selenium_hub
- AUTO_RECORD=true
# Docker-Android for mobile website testing with chrome browser
# Chrome browser exists only for version 7.0 and 7.1.1
samsung_galaxy_web_7.1.1:
image: butomo1989/docker-android-x86-8.1
privileged: true
# Increase scale number if needed
#scale: 1
depends_on:
- selenium_hub
- real_device
ports:
- 6080
volumes:
- ../video-samsung_7.1.1:/tmp/video
environment:
- DEVICE=Samsung Galaxy S6
- CONNECT_TO_GRID=true
- APPIUM=true
- SELENIUM_HOST=selenium_hub
- MOBILE_WEB_TEST=true
- AUTO_RECORD=true
# Docker-Android for mobile website testing with default browser
# Default browser exists only for version 5.0.1, 5.1.1 and 6.0
samsung_galaxy_web_5.1.1:
image: butomo1989/docker-android-x86-5.1.1
privileged: true
# Increase scale number if needed
#scale: 1
depends_on:
- selenium_hub
- real_device
ports:
- 6080
volumes:
- ../video-samsung_5.1.1:/tmp/video
environment:
- DEVICE=Samsung Galaxy S6
- CONNECT_TO_GRID=true
- APPIUM=true
- SELENIUM_HOST=selenium_hub
- MOBILE_WEB_TEST=true
- AUTO_RECORD=true

View File

@@ -0,0 +1,14 @@
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
creationTimestamp: null
labels:
io.kompose.service: nexus-7.1.1-claim0
name: nexus-7.1.1-claim0
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 100Mi
status: {}

View File

@@ -0,0 +1,14 @@
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
creationTimestamp: null
labels:
io.kompose.service: nexus-7.1.1-claim1
name: nexus-7.1.1-claim1
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 100Mi
status: {}

View File

@@ -0,0 +1,53 @@
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
annotations:
kompose.cmd: kompose convert -f ../kompose.yml
kompose.version: 1.1.0 (36652f6)
creationTimestamp: null
labels:
io.kompose.service: nexus-7.1.1
name: nexus-7.1.1
spec:
replicas: 1
strategy:
type: Recreate
template:
metadata:
creationTimestamp: null
labels:
io.kompose.service: nexus-7.1.1
spec:
containers:
- env:
- name: APPIUM
value: "true"
- name: AUTO_RECORD
value: "true"
- name: CONNECT_TO_GRID
value: "true"
- name: DEVICE
value: Nexus 5
- name: SELENIUM_HOST
value: selenium_hub
image: butomo1989/docker-android-x86-7.1.1
name: nexus-7.1.1
ports:
- containerPort: 6080
resources: {}
securityContext:
privileged: true
volumeMounts:
- mountPath: /root/tmp/sample_apk
name: nexus-7.1.1-claim0
- mountPath: /tmp/video
name: nexus-7.1.1-claim1
restartPolicy: Always
volumes:
- name: nexus-7.1.1-claim0
persistentVolumeClaim:
claimName: nexus-7.1.1-claim0
- name: nexus-7.1.1-claim1
persistentVolumeClaim:
claimName: nexus-7.1.1-claim1
status: {}

View File

@@ -0,0 +1,19 @@
apiVersion: v1
kind: Service
metadata:
annotations:
kompose.cmd: kompose convert -f ../kompose.yml
kompose.version: 1.1.0 (36652f6)
creationTimestamp: null
labels:
io.kompose.service: nexus-7.1.1
name: nexus-7.1.1
spec:
ports:
- name: "6080"
port: 6080
targetPort: 6080
selector:
io.kompose.service: nexus-7.1.1
status:
loadBalancer: {}

View File

@@ -0,0 +1,14 @@
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
creationTimestamp: null
labels:
io.kompose.service: real-device-claim0
name: real-device-claim0
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 100Mi
status: {}

View File

@@ -0,0 +1,14 @@
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
creationTimestamp: null
labels:
io.kompose.service: real-device-claim1
name: real-device-claim1
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 100Mi
status: {}

View File

@@ -0,0 +1,14 @@
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
creationTimestamp: null
labels:
io.kompose.service: real-device-claim2
name: real-device-claim2
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 100Mi
status: {}

View File

@@ -0,0 +1,50 @@
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
annotations:
kompose.cmd: kompose convert -f ../kompose.yml
kompose.version: 1.1.0 (36652f6)
creationTimestamp: null
labels:
io.kompose.service: real-device
name: real-device
spec:
replicas: 1
strategy:
type: Recreate
template:
metadata:
creationTimestamp: null
labels:
io.kompose.service: real-device
spec:
containers:
- env:
- name: CONNECT_TO_GRID
value: "true"
- name: SELENIUM_HOST
value: selenium_hub
image: appium/appium
name: real-device
resources: {}
securityContext:
privileged: true
volumeMounts:
- mountPath: /dev/bus/usb
name: real-device-claim0
- mountPath: /root/.android
name: real-device-claim1
- mountPath: /root/tmp
name: real-device-claim2
restartPolicy: Always
volumes:
- name: real-device-claim0
persistentVolumeClaim:
claimName: real-device-claim0
- name: real-device-claim1
persistentVolumeClaim:
claimName: real-device-claim1
- name: real-device-claim2
persistentVolumeClaim:
claimName: real-device-claim2
status: {}

View File

@@ -0,0 +1,20 @@
apiVersion: v1
kind: Service
metadata:
annotations:
kompose.cmd: kompose convert -f ../kompose.yml
kompose.version: 1.1.0 (36652f6)
creationTimestamp: null
labels:
io.kompose.service: real-device
name: real-device
spec:
clusterIP: None
ports:
- name: headless
port: 55555
targetPort: 0
selector:
io.kompose.service: real-device
status:
loadBalancer: {}

View File

@@ -0,0 +1,14 @@
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
creationTimestamp: null
labels:
io.kompose.service: samsung-galaxy-web-5.1.1-claim0
name: samsung-galaxy-web-5.1.1-claim0
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 100Mi
status: {}

View File

@@ -0,0 +1,50 @@
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
annotations:
kompose.cmd: kompose convert -f ../kompose.yml
kompose.version: 1.1.0 (36652f6)
creationTimestamp: null
labels:
io.kompose.service: samsung-galaxy-web-5.1.1
name: samsung-galaxy-web-5.1.1
spec:
replicas: 1
strategy:
type: Recreate
template:
metadata:
creationTimestamp: null
labels:
io.kompose.service: samsung-galaxy-web-5.1.1
spec:
containers:
- env:
- name: APPIUM
value: "true"
- name: AUTO_RECORD
value: "true"
- name: CONNECT_TO_GRID
value: "true"
- name: DEVICE
value: Samsung Galaxy S6
- name: MOBILE_WEB_TEST
value: "true"
- name: SELENIUM_HOST
value: selenium_hub
image: butomo1989/docker-android-x86-5.1.1
name: samsung-galaxy-web-5.1.1
ports:
- containerPort: 6080
resources: {}
securityContext:
privileged: true
volumeMounts:
- mountPath: /tmp/video
name: samsung-galaxy-web-5.1.1-claim0
restartPolicy: Always
volumes:
- name: samsung-galaxy-web-5.1.1-claim0
persistentVolumeClaim:
claimName: samsung-galaxy-web-5.1.1-claim0
status: {}

View File

@@ -0,0 +1,19 @@
apiVersion: v1
kind: Service
metadata:
annotations:
kompose.cmd: kompose convert -f ../kompose.yml
kompose.version: 1.1.0 (36652f6)
creationTimestamp: null
labels:
io.kompose.service: samsung-galaxy-web-5.1.1
name: samsung-galaxy-web-5.1.1
spec:
ports:
- name: "6080"
port: 6080
targetPort: 6080
selector:
io.kompose.service: samsung-galaxy-web-5.1.1
status:
loadBalancer: {}

View File

@@ -0,0 +1,14 @@
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
creationTimestamp: null
labels:
io.kompose.service: samsung-galaxy-web-7.1.1-claim0
name: samsung-galaxy-web-7.1.1-claim0
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 100Mi
status: {}

View File

@@ -0,0 +1,50 @@
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
annotations:
kompose.cmd: kompose convert -f ../kompose.yml
kompose.version: 1.1.0 (36652f6)
creationTimestamp: null
labels:
io.kompose.service: samsung-galaxy-web-7.1.1
name: samsung-galaxy-web-7.1.1
spec:
replicas: 1
strategy:
type: Recreate
template:
metadata:
creationTimestamp: null
labels:
io.kompose.service: samsung-galaxy-web-7.1.1
spec:
containers:
- env:
- name: APPIUM
value: "true"
- name: AUTO_RECORD
value: "true"
- name: CONNECT_TO_GRID
value: "true"
- name: DEVICE
value: Samsung Galaxy S6
- name: MOBILE_WEB_TEST
value: "true"
- name: SELENIUM_HOST
value: selenium_hub
image: butomo1989/docker-android-x86-8.1
name: samsung-galaxy-web-7.1.1
ports:
- containerPort: 6080
resources: {}
securityContext:
privileged: true
volumeMounts:
- mountPath: /tmp/video
name: samsung-galaxy-web-7.1.1-claim0
restartPolicy: Always
volumes:
- name: samsung-galaxy-web-7.1.1-claim0
persistentVolumeClaim:
claimName: samsung-galaxy-web-7.1.1-claim0
status: {}

View File

@@ -0,0 +1,19 @@
apiVersion: v1
kind: Service
metadata:
annotations:
kompose.cmd: kompose convert -f ../kompose.yml
kompose.version: 1.1.0 (36652f6)
creationTimestamp: null
labels:
io.kompose.service: samsung-galaxy-web-7.1.1
name: samsung-galaxy-web-7.1.1
spec:
ports:
- name: "6080"
port: 6080
targetPort: 6080
selector:
io.kompose.service: samsung-galaxy-web-7.1.1
status:
loadBalancer: {}

View File

@@ -0,0 +1,27 @@
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
annotations:
kompose.cmd: kompose convert -f ../kompose.yml
kompose.version: 1.1.0 (36652f6)
creationTimestamp: null
labels:
io.kompose.service: selenium-hub
name: selenium-hub
spec:
replicas: 1
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
io.kompose.service: selenium-hub
spec:
containers:
- image: selenium/hub:3.14.0-curium
name: selenium-hub
ports:
- containerPort: 4444
resources: {}
restartPolicy: Always
status: {}

View File

@@ -0,0 +1,19 @@
apiVersion: v1
kind: Service
metadata:
annotations:
kompose.cmd: kompose convert -f ../kompose.yml
kompose.version: 1.1.0 (36652f6)
creationTimestamp: null
labels:
io.kompose.service: selenium-hub
name: selenium-hub
spec:
ports:
- name: "4444"
port: 4444
targetPort: 4444
selector:
io.kompose.service: selenium-hub
status:
loadBalancer: {}

48
aks-terraform/main.tf Normal file
View File

@@ -0,0 +1,48 @@
resource "azurerm_container_service" "container_service" {
name = "k8s-docker-android"
resource_group_name = "${var.resource_group_name}"
location = "${var.resource_group_location}"
orchestration_platform = "Kubernetes"
master_profile {
count = "${var.master_count}"
dns_prefix = "${var.dns_name_prefix}-master"
}
agent_pool_profile {
name = "agentpools"
count = "${var.linux_agent_count}"
dns_prefix = "${var.dns_name_prefix}-agent"
vm_size = "${var.linux_agent_vm_size}"
}
linux_profile {
admin_username = "${var.linux_admin_username}"
ssh_key {
key_data = "${var.linux_admin_ssh_publickey}"
}
}
service_principal {
client_id = "${var.service_principal_client_id}"
client_secret = "${var.service_principal_client_secret}"
}
diagnostics_profile {
enabled = false
}
tags {
Source = "K8s with Terraform"
}
}
output "master_fqdn" {
value = "${azurerm_container_service.container_service.master_profile.fqdn}"
}
output "ssh_command_master0" {
value = "ssh ${var.linux_admin_username}@${azurerm_container_service.container_service.master_profile.fqdn} -A -p 22"
}

Some files were not shown because too many files have changed in this diff Show More