Elastic Kubernetes Service (Multi-tier Architecture)
In my last blog, I create an owncloud server. But there are some problems in that server we cant store our data permanently(persistent) and also we cant store lots of data.
If you want to see my last blog click here
To outcomes these problems. we want to store lots of data of our users. That's why we need separate database storage. For this, I use a Mysql Database to store data and also we want to make this data permanent for this we create a PVC also.
First I want to tell you my plan in short:
✶ First, create a PVC.
✶ Then create a database server. In my case, it's MySQL and mounts that PVC with folder /var/lib/mysql.
✶ Create a service with type ClusterIP.
✶ Create one more PVC.
✶ Create a server or web app. In my case, it's Owncloud and mounts that PVC with folder /var/www/html.
✶ Create a service with type LoadBalancer.
⧪ As I talk to you above this time we do this in an automated and easy way. So what I do.
I create 2 files 1 for MySQL and another for my owncloud. where I write code for everything which is required and also I create one more file which is Kustomization.yml so we do just type only 1 command.
❗Till now we talk so much so let's start in practical.
First as again create a cluster but this time we also use spot instance so as when load increase so it creates a new node and also set our budget so it's pocket friendly also.😅
Code>>>
apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig
metadata:
name: basic-cluster
region: ap-south-1
nodeGroups:
- name: ng-1
minSize: 2
maxSize: 5
instancesDistribution:
maxPrice: 0.017
instanceTypes: ["t3.small", "t3.medium"]
onDemandBaseCapacity: 0
onDemandPercentageAboveBaseCapacity: 60
spotInstancePools: 2
>>> Kubectl create cluster -f ..........
after creating that you only need to just write
>>>kubectl create -k .
you just only need to run this cmd all the 3 files which I talk above is on that folder.
Let me show you code also >>>
----------------------------------
Mysql file
apiVersion: v1
kind: Service
metadata:
name: owncloud-mysql
labels:
app: owncloud
spec:
ports:
- port: 3306
selector:
app: owncloud
tier: mysql
clusterIP: None
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mysql-pv-claim
labels:
app: owncloud
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 20Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: owncloud-mysql
labels:
app: owncloud
spec:
selector:
matchLabels:
app: owncloud
tier: mysql
strategy:
type: Recreate
template:
metadata:
labels:
app: owncloud
tier: mysql
spec:
containers:
- image: mysql:5.6
name: mysql
env:
- name: MYSQL_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: mysql-pass
key: password
ports:
- containerPort: 3306
name: mysql
volumeMounts:
- name: mysql-persistent-storage
mountPath: /var/lib/mysql
volumes:
- name: mysql-persistent-storage
persistentVolumeClaim:
claimName: mysql-pv-claim
----------------------------------
owncloud file
apiVersion: v1
kind: Service
metadata:
name: owncloud
labels:
app: owncloud
spec:
ports:
- port: 80
selector:
app: owncloud
tier: frontend
type: LoadBalancer
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: oc-pv-claim
labels:
app: owncloud
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 20Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: owncloud
labels:
app: owncloud
spec:
selector:
matchLabels:
app: owncloud
tier: frontend
strategy:
type: Recreate
template:
metadata:
labels:
app: owncloud
tier: frontend
spec:
containers:
- image: owncloud
name: owncloud
ports:
- containerPort: 80
name: owncloud
volumeMounts:
- name: owncloud-persistent-storage
mountPath: /var/www/html
volumes:
- name: owncloud-persistent-storage
persistentVolumeClaim:
claimName: oc-pv-claim
-----------------------------------
And final file >> Kustomization.yml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
secretGenerator:
- name: mysql-pass
literals:
- password=redhat
resources:
- mysql-deployment.yaml
- owncloud-deployment.yaml
-------------------------------------
After that output comes up as you know for the output you need to put the external IP on the browser.
Finally, now you see your web app or server which is fully not fully but ya most of the part is managed by AWS.
Output in my case:
But here not my work is complete maybe your's completed as because I use owncloud and in owncloud, we need to give the database name after launch. So as you see above I give my external database information.
After that successful connection to my database. It shows page like:
Finally, Now after login that it shows you:
I do my best to do this project very simple and clear.
I will come back with new project stay stunned with me...
Thank you for reading...
No comments:
Post a Comment