Launching Joomla With Amazon EKS

Launching Joomla With Amazon EKS

What is AWS EKS?

Amazon Elastic Kubernetes Service (Amazon EKS) is a managed service that makes it easy for you to run Kubernetes on AWS without needing to install and operate your own Kubernetes clusters. Kubernetes is an open-source system for automating the deployment, scaling, and management of containerized applications.

What is Joomla?

Joomla is a free and open-source content management system (CMS) for publishing web content, developed by Open Source Matters, Inc. It is built on a model-view-controller web application framework that can be used independently of the CMS.

Task :

We are going to going create a kubernetes cluster using EKS and by using kubernetes we deploy two deployments first is Joomla (For our CMS site..) and second is Mysql database to store your joomla sites data.

Next we integrate our EKS cluster with further aws services such ELB , EFS to make to balance the load and make our Deployment's data persistent.These entire things are done using CLI.

For Launching this setup first we need some software:

No alt text provided for this image

We have to create the AWS IAM user:

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

Now we have to configure the AWS account using cli. In my case, I already configure my AWS profile but you can configure using the access key and sercet key which you get when you create AWS IAM user.

No alt text provided for this image

Now , firstly we have to create EKS-cluster using the below code:

apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig

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

nodeGroups:
   - name: ng1
     desiredCapacity: 2
     instanceType: t2.micro
     ssh:
        publicKeyName: mykey70600
   - name: ng2
     desiredCapacity: 2
     instanceType: t2.micro
     ssh:
     
        publicKeyName: mykey70600 

Create the cluster using this command

eksctl create cluster -f cluster.yml

No alt text provided for this image

Now when we create the cluster then instance, security group and cloudFormation is created

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

Now create a config file by using this config file we can access the EKS cluster from windows CLI.

kubectl config view
aws eks update-kubeconfig — name niscluster


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

Now we have to create EFS. I use EFS because I need a shared memory(storage) among all the pods.

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

Before going to the main file creation we have to install one software in all the nodes manually by going inside each EC2 instance.

sudo yum install amazon-efs-utils -y

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

Now go to the main project means creating the yml files

we have to create kustomization file for deploying the application.

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
secretGenerator:
  -    name: mysql-secret
       literals:
        -   password=redhat123
        -   userpass=nishant123
resources:
   -   efs-provisioner.yml
   -   role.yml
   -   storage.yml
   -   deploy-mysql.yml
   -    
   -   deploy-joomla.yml



First of all we have to create the efs-provisioner.yml file

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-1b1399ca
            - name: AWS_REGION
              value: ap-south-1
            - name: PROVISIONER_NAME
              value: nis-provisioner/aws-efs
          volumeMounts:
            - name: pv-volume
              mountPath: /persistentvolumes
      volumes:
        - name: pv-volume
          nfs:
            server: fs-1b1399ca.efs.ap-south-1.amazonaws.com
            path: /


create this file using

   kubectl create -f efs-provisioner.yml 


create role.yml - this file provide additional security and power to the provisioner.

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


create this file using

   kubectl create -f role.yml


create-storage.yml - we create the pvc and storage for making data persistent.

kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
  name: aws-efs
provisioner: nis-provisioner/aws-efs
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: efs-joomla
  annotations:
    volume.beta.kubernetes.io/storage-class: "aws-efs"
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 1Gi
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: efs-mysql
  annotations:
    volume.beta.kubernetes.io/storage-class: "aws-efs"
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 1Gi


create this file using

    kubectl create -f storage.yml


Now come on the main file, deploy-mysql.yml - using this file we create mysql database for joomla.

apiVersion: v1
kind: Service
metadata:
  name: joomla-mysql
  labels:
    app: joomla
spec:
  ports:
    - port: 3306
  selector:
    app: joomla
    tier: mysql
  clusterIP: None
---
apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
  name: joomla-mysql
  labels:
    app: joomla
spec:
  selector:
    matchLabels:
      app: joomla
      tier: mysql
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: joomla
        tier: mysql
    spec:
      containers:
      - image: mysql:5.6
        name: mysql
        env:
        - name: MYSQL_ROOT_PASSWORD
          valueFrom:
            secretKeyRef:
              name: mysql-secret
              key: password
        ports:
        - containerPort: 3306
          name: mysql
        volumeMounts:
        - name: mysql-persistent-storage
          mountPath: /var/lib/mysql
      volumes:
      - name: mysql-persistent-storage
        persistentVolumeClaim:
          claimName: efs-mysql



create this file using

    kubectl create -f deploy-mysql.yml


deploy-joomla.yaml - this creates our main deployment joomla.

apiVersion: v1
kind: Service
metadata:
  name: joomla
  labels:
    app: joomla
spec:
  ports:
    - port: 80
  selector:
    app: joomla
    tier: frontend
  type: LoadBalancer
---
apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
  name: joomla
  labels:
    app: joomla
spec:
  selector:
    matchLabels:
      app: joomla
      tier: frontend
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: joomla
        tier: frontend
    spec:
      containers:
      - image: joomla
        name: joomla
        env:
        - name: JOOMLA_DB_HOST
          value: joomla-mysql
        - name: JOOMLA_DB_PASSWORD
          valueFrom:
            secretKeyRef:
              name: mysql-secret
              key: password
        ports:
        - containerPort: 80
          name: joomla
        volumeMounts:
        - name: joomla-persistent-storage
          mountPath: /var/www/html
      volumes:
      - name: joomla-persistent-storage
        persistentVolumeClaim:
          claimName: efs-joomla


create this file using

    kubectl create -f deploy-joomla.yml



Now run the kustomization file to build the entire setup

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

Now wait for sometime until the podsand deployment are not created. After sometime I access the pods.

No alt text provided for this image

Joomla successfully deploy Now time to delete all the things

first of all delete kustomization file by typing

      kubectl delete -k .
       

After delete the kustomization file you have to delete EFS

After deleting this we have to delete the cluster

     eksctl delete cluster -f cluster.yml


No alt text provided for this image

GITHUB URL:

THANK YOU !!!


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

Nishant Singh的更多文章

社区洞察

其他会员也浏览了