Skip to content

Commit 6fc9019

Browse files
committed
Welcome to Stack Simplify
1 parent 4f6271a commit 6fc9019

21 files changed

+416
-132
lines changed

24-Azure-AKS-Terraform/24-05-Create-AKS-Cluster-Custom-VNET/README.md

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
# Create AKS Cluster using Custom Virtual Network
22

33
## Step-01: Introduction
4-
4+
- Create a Custom Virtual Network and Subnet
5+
- Reference the same in AKS Cluster and Node Pools linux and windows
6+
- Create the AKS Cluster with nodepools on custom vnet
7+
- Deploy sample Apps and test
8+
- Destroy the cluster after tests
59

610
## Step-02: Create Virtual Network and AKS Default Subnet
711
- Create Virtual Network using Terraform
@@ -40,24 +44,24 @@ terraform {
4044
```
4145

4246
## Step-04: Update variables.tf with environment name
43-
- We are also going to change cluster environment name as prod2
47+
- We are also going to change cluster environment name as dev2
4448
```
4549
# Azure AKS Environment Name
4650
variable "environment" {
4751
type = string
4852
description = "This variable defines the Environment"
49-
default = "prod2"
53+
default = "dev2"
5054
}
5155
```
5256

5357
## Step-05: Add below for default system, Linux, windows nodepools
5458
- We will add this in following files
55-
- 07-aks-cluster.tf
59+
- 07-aks-cluster.tf in default node pool
5660
- 08-aks-cluster-linux-user-nodepools.tf
5761
- 09-aks-cluster-windows-user-nodepools.tf
5862
```
5963
# AKS Default Subnet ID
60-
vnet_subnet_id = azurerm_subnet.aks-default.id
64+
vnet_subnet_id = azurerm_subnet.aks-default.id
6165
```
6266

6367
## Step-06: Deploy Terraform Resources
@@ -83,13 +87,13 @@ terraform apply
8387
## Step-07: Verify if Nodepools added successfully
8488
```
8589
# List Node Pools
86-
az aks nodepool list --resource-group terraform-aks --cluster-name terraform-aks-prod2 --output table
90+
az aks nodepool list --resource-group terraform-aks-dev2 --cluster-name terraform-aks-dev2-cluster --output table
8791
8892
# List Nodes using Labels
8993
kubectl get nodes -o wide
9094
kubectl get nodes -o wide -l nodepoolos=linux
9195
kubectl get nodes -o wide -l nodepoolos=windows
92-
kubectl get nodes -o wide -l environment=production
96+
kubectl get nodes -o wide -l environment=dev2
9397
```
9498

9599

@@ -99,7 +103,7 @@ kubectl get nodes -o wide -l environment=production
99103
- Dotnet App to Windows Nodepool
100104
```
101105
# Change Directory
102-
cd 24-04-Create-AKS-NodePools-using-Terraform/
106+
cd 24-05-Create-AKS-Cluster-Custom-VNET/
103107
104108
# Deploy All Apps
105109
kubectl apply -R -f kube-manifests/
@@ -128,7 +132,7 @@ http://<public-ip-of-windows-app>
128132
## Step-08: Destroy our Terraform Cluster
129133
```
130134
# Change Directory
131-
cd 24-04-Create-AKS-NodePools-using-Terraform/v3-terraform-manifests-aks
135+
cd 24-05-Create-AKS-Cluster-Custom-VNET/terraform-manifests-aks-custom-vnet
132136
133137
# Destroy all our Terraform Resources
134138
terraform destroy
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: app1-nginx-deployment
5+
labels:
6+
app: app1-nginx
7+
spec:
8+
replicas: 1
9+
selector:
10+
matchLabels:
11+
app: app1-nginx
12+
template:
13+
metadata:
14+
labels:
15+
app: app1-nginx
16+
spec:
17+
containers:
18+
- name: app1-nginx
19+
image: stacksimplify/kube-nginxapp1:1.0.0
20+
ports:
21+
- containerPort: 80
22+
# To schedule pods on based on NodeSelectors
23+
nodeSelector:
24+
app: system-apps
25+
26+
27+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: app1-nginx-clusterip-service
5+
labels:
6+
app: app1-nginx
7+
spec:
8+
type: LoadBalancer
9+
selector:
10+
app: app1-nginx
11+
ports:
12+
- port: 80
13+
targetPort: 80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
apiVersion: storage.k8s.io/v1
2+
kind: StorageClass
3+
metadata:
4+
name: managed-premium-retain-sc
5+
provisioner: kubernetes.io/azure-disk
6+
reclaimPolicy: Retain # Default is Delete, recommended is retain
7+
volumeBindingMode: WaitForFirstConsumer # Default is Immediate, recommended is WaitForFirstConsumer
8+
allowVolumeExpansion: true
9+
parameters:
10+
storageaccounttype: Premium_LRS # or we can use Standard_LRS
11+
kind: managed # Default is shared (Other two are managed and dedicated)
12+
13+
14+
##############################################################################
15+
# Note-1:
16+
#volumeBindingMode: Immediate - This setting implies that the PersistentVolumecreation,
17+
#followed with the storage medium (Azure Disk in this case) provisioning is triggered as
18+
#soon as the PersistentVolumeClaim is created.
19+
20+
# Note-2:
21+
# volumeBindingMode: WaitForFirstConsumer
22+
#By default, the Immediate mode indicates that volume binding and dynamic provisioning
23+
#occurs once the PersistentVolumeClaim is created. For storage backends that are
24+
#topology-constrained and not globally accessible from all Nodes in the cluster,
25+
#PersistentVolumes will be bound or provisioned without knowledge of the Pod's scheduling
26+
#requirements. This may result in unschedulable Pods.
27+
#A cluster administrator can address this issue by specifying the WaitForFirstConsumer
28+
#mode which will delay the binding and provisioning of a PersistentVolume until a
29+
#Pod using the PersistentVolumeClaim is created. PersistentVolumes will be selected or
30+
#provisioned conforming to the topology that is specified by the Pod's scheduling
31+
#constraints.
32+
##############################################################################
33+
# Note-3:
34+
#reclaimPolicy: Delete - With this setting, as soon as a PersistentVolumeClaim is deleted,
35+
#it also triggers the removal of the corresponding PersistentVolume along with the
36+
#Azure Disk.
37+
#We will be surprised provided if we intended to retain that data as backup.
38+
# reclaimPolicy: retain - Disk is retained even when PVC is deleted - Recommended Option
39+
40+
# Note-4:
41+
# Both reclaimPolicy: Delete and volumeBindingMode: Immediate are default settings
42+
##############################################################################
43+
# Note-5:
44+
# Additional Reference
45+
# https://kubernetes.io/docs/concepts/storage/storage-classes/#azure-disk
46+
# Managed: When managed used, that disk is persisted for the Lifecycle of the cluster.
47+
# If we delete cluster, it will delete the disk
48+
##############################################################################
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: v1
2+
kind: PersistentVolumeClaim
3+
metadata:
4+
name: azure-managed-disk-pvc
5+
spec:
6+
accessModes:
7+
- ReadWriteOnce
8+
storageClassName: managed-premium-retain-sc
9+
resources:
10+
requests:
11+
storage: 5Gi
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: usermanagement-dbcreation-script
5+
data:
6+
mysql_usermgmt.sql: |-
7+
DROP DATABASE IF EXISTS webappdb;
8+
CREATE DATABASE webappdb;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: mysql
5+
spec:
6+
replicas: 1
7+
selector:
8+
matchLabels:
9+
app: mysql
10+
strategy:
11+
type: Recreate
12+
template:
13+
metadata:
14+
labels:
15+
app: mysql
16+
spec:
17+
containers:
18+
- name: mysql
19+
image: mysql:5.6
20+
env:
21+
- name: MYSQL_ROOT_PASSWORD
22+
value: dbpassword11
23+
ports:
24+
- containerPort: 3306
25+
name: mysql
26+
volumeMounts:
27+
- name: mysql-persistent-storage
28+
mountPath: /var/lib/mysql
29+
- name: usermanagement-dbcreation-script
30+
mountPath: /docker-entrypoint-initdb.d #https://hub.docker.com/_/mysql Refer Initializing a fresh instance
31+
volumes:
32+
- name: mysql-persistent-storage
33+
persistentVolumeClaim:
34+
claimName: azure-managed-disk-pvc
35+
- name: usermanagement-dbcreation-script
36+
configMap:
37+
name: usermanagement-dbcreation-script
38+
# To schedule pods on based on NodeSelectors
39+
nodeSelector:
40+
app: java-apps
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: mysql
5+
spec:
6+
selector:
7+
app: mysql
8+
ports:
9+
- port: 3306
10+
clusterIP: None # This means we are going to use Pod IP
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: usermgmt-webapp
5+
labels:
6+
app: usermgmt-webapp
7+
spec:
8+
replicas: 1
9+
selector:
10+
matchLabels:
11+
app: usermgmt-webapp
12+
template:
13+
metadata:
14+
labels:
15+
app: usermgmt-webapp
16+
spec:
17+
initContainers:
18+
- name: init-db
19+
image: busybox:1.31
20+
command: ['sh', '-c', 'echo -e "Checking for the availability of MySQL Server deployment"; while ! nc -z mysql 3306; do sleep 1; printf "-"; done; echo -e " >> MySQL DB Server has started";']
21+
containers:
22+
- name: usermgmt-webapp
23+
image: stacksimplify/kube-usermgmt-webapp:1.0.0-MySQLDB
24+
imagePullPolicy: Always
25+
ports:
26+
- containerPort: 8080
27+
env:
28+
- name: DB_HOSTNAME
29+
value: "mysql"
30+
- name: DB_PORT
31+
value: "3306"
32+
- name: DB_NAME
33+
value: "webappdb"
34+
- name: DB_USERNAME
35+
value: "root"
36+
- name: DB_PASSWORD
37+
value: "dbpassword11"
38+
# To schedule pods on based on NodeSelectors
39+
nodeSelector:
40+
app: java-apps
41+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: usermgmt-webapp-service
5+
labels:
6+
app: usermgmt-webapp
7+
spec:
8+
type: LoadBalancer
9+
selector:
10+
app: usermgmt-webapp
11+
ports:
12+
- port: 80
13+
targetPort: 8080

0 commit comments

Comments
 (0)