DEPLOYING OWNCLOUD AND MYSQL OVER EKS

DEPLOYING OWNCLOUD AND MYSQL OVER EKS

Goal: 

To create an EKS cluster using AWS

Deploying OwnCloud and MySQL on EKS

Using EFS for storage

Step1: Creating EKS cluster file with 2 node groups: ng-1 and ng-mixed(it provides on spot instances). Here, the public key is also attached to access the nodes.

cluster.yml

apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig




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




nodeGroups:
   - name: ng-1
     instanceType: t2.micro
     desiredCapacity: 2
     ssh: 
         publicKeyName: cliclass
   - name: ng-mixed
     minSize: 2
     maxSize: 5
     instancesDistribution:
      maxPrice: 0.017
      instanceTypes: ["t3.small", "t3.medium"] # At least one instance type should be specified
      onDemandBaseCapacity: 0
      onDemandPercentageAboveBaseCapacity: 50
      spotInstancePools: 2
     ssh: 
         publicKeyName: cliclass

Step 2: Login AWS from the command line with an already defined IAM role and then launching the cluster.

No alt text provided for this image
No alt text provided for this image

It will take approximately 10 to 12 minutes to launch the cluster.

Step 3: Configuring kubectl so that you can connect to an Amazon EKS cluster which we have created above.

>aws eks update-kubeconfig --name lwcluster

Step 4: Creating ClusterRoleBinding to give access to the cluster created in a specific namespace.

create-rbac.yml

---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
  name: nfs-provisioner-role-binding
subjects:
  - kind: ServiceAccount
    name: default
    namespace: akarshns
roleRef:
  kind: ClusterRole
  name: cluster-admin
  apiGroup: rbac.authorization.k8s.io

 

Step 5: Setting up EFS for giving storage to the nodes created above in step 2. Here EFS is used instead of EBS because EFS allows you to mount the file system across multiple regions and instances whereas EBS is only accessible from a single EC2 instance in particular AWS region.

In AWS EFS service, same Shared Node Security Group is to be assigned as security group in EFS to all the availability zones in the same VPC where cluster nodes were launched.

No alt text provided for this image

After creating the EFS, it gives File System ID and a DNS Name which will be used in next step.

Step 6: Launching EFS-Provisioner, it allows you to mount EFS storage as Persistent Volumes in Kubernetes.

create-efs-provisioner.yml

kind: Deployment
apiVersion: apps/v1
metadata:
  name: efs-provisioner
spec:
  selector:
    matchLabels:
      app: efs-provisioner
  replicas: 1
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: efs-provisioner
    spec:
      containers:
        - name: efs-provisioner
          image: quay.io/external_storage/efs-provisioner:v0.1.0
          env:
            - name: FILE_SYSTEM_ID
              value: fs-b01d9661
            - name: AWS_REGION
              value: ap-south-1
            - name: PROVISIONER_NAME
              value: Akarsh-pro/aws-efs
          volumeMounts:
            - name: pv-volume
              mountPath: /persistentvolumes
      volumes:
        - name: pv-volume
          nfs:
            server: fs-b01d9661.efs.ap-south-1.amazonaws.com
            path: /

Step 7: Claiming Persistent Volume Storage from EFS for MySQL and OwnCloud.

create-storage.yml

kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
  name: aws-efs
provisioner: Akarsh-pro/aws-efs
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: efs-wordpress
  annotations:
    volume.beta.kubernetes.io/storage-class: "aws-efs"
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 2Gi
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: efs-mysql
  annotations:
    volume.beta.kubernetes.io/storage-class: "aws-efs"
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 2Gi

Step 8: Launching Kubernetes Deployment of MySQL and OwnCloud.

mysql.yml

apiVersion: v1
kind: Service
metadata:
  name: my-sql-server
  labels: 
    env: mysqlserver
spec:
  clusterIP: None
  ports:
    - port: 3306
  selector:
    env: mysqlserver
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-sql-server
  labels:
    env: mysqlserver
spec:
  replicas: 1
  selector:
    matchLabels:
      env: mysqlserver
  template:
    metadata:
      name: mysqlpod
      labels:
        env: mysqlserver
    spec:
      containers:
      - name: mysqlcont1
        image: mysql:5.6
        env:
        - name: MYSQL_ROOT_PASSWORD
          value: redhat
        - name: MYSQL_DATABASE
          value: mydb
        - name: MYSQL_USER
          value: Akarsh
        - name: MYSQL_PASSWORD
          value: Agarwal
        ports:
        - containerPort: 3306
          name: mysqlcont1
        volumeMounts:
        - name: myvol-1
          mountPath: /var/lib/mysql
      volumes:
      - name: myvol-1
        persistentVolumeClaim: 
         claimName: efs-mysql

owncloud.yml

apiVersion: v1
kind: Service
metadata:
  name: myowncloud
  labels:
    env: owncloud
spec:
  selector:
    env: owncloud
  ports:
    - port: 80
  type: LoadBalancer
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-owncloud
  labels:
    env: owncloud
spec:
  replicas: 1
  selector:
    matchLabels:
      env: owncloud
  template:
    metadata:
      name: myowncloudpod
      labels:
        env: owncloud
    spec:
      containers:
      - name: myown-cont-1
        image: owncloud:10.0.10-apache
        env:
        - name: OWNCLOUD_DB_HOST
          value: my-sql-server
        - name: OWNCLOUD_DB_USER
          value: Akarsh
        - name: OWNCLOUD_DB_PASSWORD
          value: Agarwal
        - name: OWNCLOUD_DB_NAME
          value: mydb
        ports:
        - containerPort: 80
          name: myown-cont-1
        volumeMounts:
        - name: myvol-2
          mountPath: /var/www/html
      volumes:
      - name: myvol-2
        persistentVolumeClaim:
         claimName: efs-wordpress

kustomization.yml

apiVersion: kustomize.config.k8s.io/v1beta1
kind:  Kustomization
resources:
  - create-efs-provisioner.yaml
  - create-rbac.yaml
  - create-storage.yaml
  - mysql.yml

  - owncloud.yml

Launching all of the above:

> kubectl create -k .

All the services launched:

No alt text provided for this image
No alt text provided for this image

Using external IP, we can access the owncloud site.

No alt text provided for this image


OwnCloud and MySQL, both have persistent storage and are launched with deployment, so if any pod goes down for any reason, it launches another one without any downtime and its data is persistent.

No alt text provided for this image


Step 9: Setting up Helm and Tiller for using Prometheus and Grafana.

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image


Thanks for reading.




To view or add a comment, sign in

More articles by Akarsh Agarwal

  • VGG FACE RECOGNITION

    Problem Statement: Create a project using transfer learning solving various problems like Face Recognition, Image…

  • TASK6

    Perform third task with the help of Jenkins coding file ( called as jenkinsfile approach ) and perform the with…

    1 Comment
  • TASK 5

    Integrate Prometheus and Grafana and perform in following way: 1. Deploy them as pods on top of Kubernetes by creating…

    1 Comment
  • TASK4

    Create A dynamic Jenkins cluster and perform task-3 using the dynamic Jenkins cluster. Steps to proceed as: 1.

    1 Comment
  • DTASK3

    DevOps Task 3: Perform task on top of Kubernetes where we use Kubernetes resources like Pods, ReplicaSet, Deployment…

    1 Comment
  • TEAM_VISION

    💐If you are thinking like Why Vision? Its not because of its definition which you when search on wikipedia viz. the…

Others also viewed

Explore content categories