Deploy OwnCloud webapp on AWS using EKS

Deploy OwnCloud webapp on AWS using EKS

Hey guys!! I am back with another article based on the Elastic Kubernetes Service (EKS) under the umbrella of AWS.

A brief introduction

Kubernetes is an open-source system for automating the deployment, scaling, and management of containerized applications. EKS is the managed AWS service that makes it easy to run Kubernetes on AWS without the need to maintain own Kubernetes setup. Amazon EKS is also integrated with many AWS services to provide scalability and security for our applications, like IAM for authenticity, VPC for network isolation, LoadBalancing for traffic management and so on.

In this project, we will deploy the webapp of OwnCloud on the AWS platform using the service of EKS aided by CloudFormation. OwnCloud is a suite of client–server software for creating and using file hosting services. It is functionally similar to the widely used application DropBox. To setup the same, we would also need a database system that will store the user credentials for OwnCloud. Let's use MySQL as database in this case.

Pre-Requisites for the task : i) AWS CLI installed in base system ii) Basic knowledge on kubectl commands iii) eksctl installed and path added to Environment Variables iv) AWS IAM user with AdministratorAccess policy given.

Steps to be performed

  1. We would start with configuring the AWS IAM user using the credentials that had been provided while creating the user.
No alt text provided for this image

2. Next up is to check eksctl is properly installed or not using the following command.

No alt text provided for this image

Fine! All requirements have been setup and checked. Now let's start with setting up the infrastructure.

3. We require a YAML file to setup an EKS cluster on AWS. The cluster.yml file is given below:-

apiversion: eksctl.io/v1alpha5
Kind: ClusterConfig


metadata:
  name: ekscluster
  region: ap-south-1


nodeGroups:
  - name: ng-1
    instanceType: t2.micro
    desiredCapacity: 2
    ssh:
      publicKeyName: newkey
  - name: ng-mixed
    minSize: 1
    maxSize: 3
    instancesDistribution:
      maxPrice: 0.050
      instanceTypes: ["t3.micro", "t3.small"]
      onDemandBaseCapacity: 0
      onDemandPercentageAboveBaseCapacity: 80
      spotInstancePools: 2
    ssh:
      publicKeyName: newkey

4. Next we need a YAML file to deploy the MySQL database. The storage for the database will be a PVC claimed from a PV, mounted to the path /var/lib/mysql. The database_deploy.yml file is given below:-

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-pvc
  labels:
    app: owncloud
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi
---
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:latest
        name: mysql
        env:
        - name: MYSQL_ROOT_PASSWORD
          valueFrom:
            secretKeyRef:
              name: mysql-pass
              key: password
        - name: MYSQL_USER
          value: saranya
        - name: MYSQL_PASSWORD
        ports:
        - containerPort: 3306
          name: mysql
        volumeMounts:
        - name: mysql-pv
          mountPath: /var/lib/mysql
      volumes:
      - name: mysql-pv
        persistentVolumeClaim:
          claimName: mysql-pvc
         

5. After this, we require to make a YAML file for the webapp deployment. The storage for the same will also be taken from a PVC claimed from a PV, mounted to the path /var/www/html. The owncloud_deploy.yml file is as below:-

apiVersion: v1
kind: Service
metadata:
  name: owncloud
  labels:
    app: owncloud
spec:
  ports:
  - port: 80
    nodePort: 30039
  selector:
    app: owncloud
    tier: frontend
  type: LoadBalancer
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: owncloud-pvc
  labels:
    app: owncloud
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi
---
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:latest
        name: owncloud
        env:
        - name: MYSQL_ROOT_PASSWORD
          valueFrom:
            secretKeyRef:
              name: mysql-pass
              key: password
        - name: MYSQL_USER
          value: saranya
        - name: MYSQL_PASSWORD
          valueFrom:
            secretKeyRef:
              name: mysqluser-pass
              key: myuserpassword
        - name: MySQL_DATABASE
          value: mysqldatabase
        ports:
        - containerPort: 80
          name: owncloud
        volumeMounts:
        - name: owncloud-pv
          mountPath: /var/www/html
      volumes:
      - name: owncloud-pv
        persistentVolumeClaim:
          claimName: owncloud-pvc

        

6. In order to bind both the deployment files together so that one command could setup both the deployments, we punch them together in a kustomization.yml file as below:-

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
secretGenerator:
 - name: mysql-pass
   literals:
      - password=sara1
 - name: mysqluser-pass
   literals:
      - myuserpassword=sara2
resources:
   - database_deploy.yml
   - owncloud_deploy.yml

( I have uploaded all the YAML files in my GitHub and provided its link in my post. Please visit my GitHub repository for further reference to these files.)

Once all the files are created, we can now move on to setup the infrastructure. First, we will create the EKS cluster with the following command.

eksctl create cluster -f mycluster.yml

This process will take around 15-20 minutes to setup the cluster along with the required EC2 instances in region ap-south-1. Once the setup is done, we can check our clutser using the command:-

No alt text provided for this image

Next, we need to update our kube-config file so that kubectl can connect to our EKS cluster and we can run the kubectl commands without error. The command to be used is:-

aws eks update -kubeconfig --name ekscluster

Now, its time for our deployments, both database and webapp to be created. For this, we have already made our kustomization.yml file which when run will deploy both he resources automatically. Command for the same is:-

kubectl create -k .
No alt text provided for this image

All the resources have been successfully created! Now, its time to get the URL on which our webapp has been deployed by EKS. For this, we will use the command:-

kubectl get all
No alt text provided for this image

The external IP given under service/owncloud is the required URL on which OwnCloud has been deployed. We can view the login dashboard of OwnCloud by browsing the URL.

No alt text provided for this image

That's it! Webapp deployed on AWS using EKS, and that too done only on CLI mode, not even visiting the AWS webUI once!!

To be noted : For launching the cluster, we will be charged by AWS bacause EKS and the instance t2.small (used in the cluster) are not under the AWS free tier. So, it is highly recommended that when the work is over, the whole setup should be destroyed as soon as possible to reduce the charges using the following commands:-

kubectl delete -k .
eksctl delete cluster ekscluster
No alt text provided for this image
No alt text provided for this image

That's all guys!!

THANK YOU :)

Hriddha Bhowmik

Software Engineer, Capgemini India ???? Guidewire Certified Associate Developer ?

4 年

Great job ??

Chirag Chaudhuri

RPA Developer | SDE - 1 @HighRadius Technologies

4 年

Nice work! Keep it up????

Saptarsi Roy

Software Engineer 1 at Dell Technologies || Google Certified Associate Cloud Engineer || Redhat certified Engineer || EX-180 Certified || ARTH-2020 Learner @LW

4 年

Cool ????

要查看或添加评论,请登录

Saranya Chattopadhyay的更多文章

社区洞察

其他会员也浏览了