aws terraform_aws rds terraform kubernetes wordpress

aws terraform

Heyy EveryOne ..!! In this Blog i will explain you How tO Launch Wordpress Application On The Top Of Kubernetes (Minikube) with Amazon RDS as Database Using Terraform .

大家好.. !! 在本博客中,我将向您解释如何使用Terraform在Amazon RDS作为数据库的Kubernetes(Minikube)顶部启动Wordpress应用程序。

项目介绍 :- (Project Description :-)

#DescripTion Of projectWrite an Infrastructure as code using Terraform, which automatically deploy the WordPress applicationOn AWS, use RDS service for the relational database for WordPress application.Deploy WordPress as a container either on top of Minikube or EKS or Fargate service on AWS.The WordPress application should be accessible from the public world if deployed on AWS or through workstation if deployed on Minikube.
Image for post

Amazon Web Services (AWS) is a subsidiary of Amazon providing on-demand cloud computing platforms and APIs to individuals, companies, and governments, on a metered pay-as-you-go basis. These cloud computing web services provide a variety of basic abstract technical infrastructure and distributed computing building blocks and tools. One of these services is Amazon Elastic Compute Cloud (EC2), which allows users to have at their disposal a virtual cluster of computers, available all the time, through the Internet. AWS’s version of virtual computers emulates most of the attributes of a real computer, including hardware central processing units (CPUs) and graphics processing units (GPUs) for processing; local/RAM memory; hard-disk/SSD storage; a choice of operating systems; networking; and pre-loaded application software such as web servers, databases, and customer relationship management (CRM).

Amazon Web Services ( AWS )是Amazon的子公司, 按按需付费方式为个人,公司和政府提供按需 云计算 平台API 。 这些云计算Web服务提供了各种基本的抽象技术基础结构以及分布式计算构造块和工具。 这些服务之一是Amazon Elastic Compute Cloud (EC2),它使用户可以随时通过Internet使用随时可用的虚拟 计算机集群 。 AWS的虚拟计算机版本模拟了真实计算机的大多数属性,包括用于处理的硬件中央处理器 (CPU)和图形处理器 (GPU)。 本地/ RAM内存; 硬盘/ SSD存储 ; 选择操作系统; 联网; 以及预装的应用程序软件,例如Web服务器数据库客户关系管理 (CRM)。

Image for post

Amazon Relational Database Service (or Amazon RDS) is a distributed relational database service by Amazon Web Services (AWS). It is a web service running “in the cloud” designed to simplify the setup, operation, and scaling of a relational database for use in applications. Administration processes like patching the database software, backing up databases and enabling point-in-time recovery are managed automatically. Scaling storage and compute resources can be performed by a single API call as AWS does not offer an ssh connection to RDS instances.

Amazon Relational Database Service (或Amazon RDS )是Amazon Web Services (AWS)的分布式关系数据库服务。 它是一种“在云端”运行的Web服务 旨在简化用于应用程序的关系数据库的设置,操作和扩展 。 系统会自动管理诸如修补数据库软件,备份数据库和启用时间点恢复之类的管理过程。 扩展存储和计算资源可以通过单个API调用执行,因为AWS不提供与RDS实例的ssh连接。

Image for post

Terraform is an open-source infrastructure as code software tool created by HashiCorp. Users define and provision data center infrastructure using a declarative configuration language known as HashiCorp Configuration Language (HCL), or optionally JSON.Terraform manages external resources (such as public cloud infrastructure, private cloud infrastructure, network appliances, software as a service, and platform as a service) with “providers”. HashiCorp maintains an extensive list of official providers, and can also integrate with community-developed providers. Users can interact with Terraform providers by declaring resources or by calling data sources. Rather than using imperative commands to provision resources, Terraform uses declarative configuration to state the desired final state. Once a user invokes Terraform on a given resource, Terraform will perform CRUD actions on the user’s behalf to accomplish the desired state. The infrastructure as code can be written as modules, promoting reusability and maintainability.

Terraform是由HashiCorp创建的作为代码软件工具的开源 基础 结构 。 用户使用称为HashiCorp配置语言(HCL)或JSON的声明性配置语言来定义和配置数据中心基础架构。Terraform管理外部资源(例如公共云基础架构,私有云基础架构,网络设备, 软件即服务平台)服务 ))与“提供者”。 HashiCorp拥有大量的官方提供程序列表,并且还可以与社区开发的提供程序集成。 用户可以通过声明资源或调用数据源来与Terraform提供程序进行交互。 Terraform使用声明性配置来声明所需的最终状态,而不是使用命令式命令来配置资源。 用户在给定资源上调用Terraform后,Terraform将代表用户执行CRUD操作以完成所需的状态。 可以将基础结构作为代码编写为模块,从而提高可重用性和可维护性。

Image for post

Kubernetes (commonly stylized as K8s) is an open-source container-orchestration system for automating computer application deployment, scaling, and management. It was originally designed by Google and is now maintained by the Cloud Native Computing Foundation. It aims to provide a “platform for automating deployment, scaling, and operations of application containers across clusters of hosts”. It works with a range of container tools, including Docker. Many cloud services offer a Kubernetes-based platform or infrastructure as a service (PaaS or IaaS) on which Kubernetes can be deployed as a platform-providing service. Many vendors also provide their own branded Kubernetes distributions.

Kubernetes (通常称为K8s )是一个开放源代码的 容器 编排系统,用于自动执行计算机应用程序的部署,扩展和管理。 它最初是由Google设计的,现在由Cloud Native Computing Foundation维护。 它的目的是提供一个“跨主机群集自动执行应用程序容器的部署,扩展和操作的平台”。 它可以与包括Docker在内的各种容器工具一起使用。 许多服务都提供了基于Kubernetes的平台或基础架构即服务( PaaSIaaS ),可以在其上将Kubernetes部署为提供平台的服务。 许多供应商还提供了自己的品牌Kubernetes发行版。

Minikube is a tool that makes it easy to run Kubernetes locally. Minikube runs a single-node Kubernetes cluster inside a Virt

Minikube is a tool that makes it easy to run Kubernetes locally. Minikube runs a single-node Kubernetes cluster inside a Virtual Machine (VM) on your laptop for users looking to try out Kubernetes or develop with it day-to-day.

Minikube是一种可以轻松在本地运行Kubernetes的工具。 Minikube在笔记本电脑的虚拟机(VM)内运行一个单节点Kubernetes集群,以供希望试用Kubernetes或每天使用它开发的用户使用。

Image for post

WordPress (WP, WordPress.org) is a free and open-source content management system (CMS) written in PHP and paired with a MySQL or MariaDB database. Features include a plugin architecture and a template system, referred to within WordPress as Themes. WordPress was originally created as a blog-publishing system but has evolved to support other types of web content including more traditional mailing lists and forums, media galleries, membership sites, learning management systems (LMS) and online stores. WordPress is used by more than 60 million websites, including 33.6% of the top 10 million websites as of April 2019, WordPress is one of the most popular content management system solutions in use.[8] WordPress has also been used for other application domains such as pervasive display systems (PDS). WordPress was released on May 27, 2003, by its founders, American developer Matt Mullenweg[1] and English developer Mike Little, as a fork of b2/cafelog. The software is released under the GPLv2 (or later) license.

WordPress ( WPWordPress.org )是一个免费的开放源代码内容管理系统 (CMS),用PHP编写并与MySQLMariaDB数据库配对。 功能包括插件体系结构模板系统 ,在WordPress中称为主题。 WordPress最初是作为博客发布系统创建的,但现已演变为支持其他类型的Web内容,包括更传统的邮件列表论坛 ,媒体库,会员站点, 学习管理系统 (LMS)和在线商店 。 截至2019年4月,WordPress已被超过6000万个网站使用,其中包括前1000万个网站中的33.6%,WordPress是当前最受欢迎的内容管理系统解决方案之一。 [8] WordPress也已用于其他应用程序领域,例如普及显示系统 (PDS)。 WordPress的创始人,美国开发人员Matt Mullenweg [1]和英国开发人员Mike Little于2003年5月27日发布了b2 / cafelog分支 。 该软件根据GPLv2 (或更高版本)许可发布。

先决条件: (Prerequisites :-)

  1. AWS AccounT .

    AWS AccounT。
  2. IAM User In The Main Account of AWS .

    AWS主账户中的IAM用户。
  3. Terraform MusT Be Installed .

    安装Terraform MusT。
  4. AWS CLI .

    AWS CLI。
  5. Minikube Should be Installed For Performing This Task .

    应该安装Minikube来执行此任务。
  6. Kubectl to be Installed .

    安装Kubectl。
  7. Terraform plugin in vs code (its n’t necessary if you are not using vscode)

    vs代码中的Terraform插件(如果您不使用vscode,则不需要此插件)

LeT’s Start

开始吧

配置AWS CLI并创建配置文件 (Configure AWS CLI and Create a Profile)

aws configure --profile 'profile_name'
Image for post

Now we are going ahead in our task so for saving our time we can start minikube .

现在我们正在执行任务,因此为了节省时间,我们可以启动minikube。

minikube start
Image for post

Now I am going to explain you the code .

现在,我将向您解释代码。

This is Our main.tf or we can say that main file which has responsibility to run the code and also it will run 2 more files as declared in depends_on block of code . and this file is the one which will show us the output

这是我们的main.tf,或者可以说是负责运行代码的主文件,并且它将再运行2个文件,如在depends_on代码块中声明的那样。 这个文件就是向我们展示输出的文件

main.tf

main.tf

Image for post
resource "null_resource" "minikubeservice" {
  provisioner "local-exec" {
    command = "minikube service list"
    
  }
  depends_on = [
      kubernetes_deployment.abhiwp,
      kubernetes_service.abhiwplb,
      aws_db_instance.abhidatabase
 
     ]
}

rdb.tf

rdb.tf

This Code will Create RDS On AWS with the name , pass, storage etc. according to our requirement . and the at the last the output block will run to get ip on the console .

此代码将根据我们的要求在AWS上使用名称,通过,存储等创建RDS。 最后一个输出块将运行以在控制台上获取ip。

Image for post
provider "aws" {
  region = "ap-south-1"
  profile = "AbhiTerras"
}
resource "aws_db_instance" "abhidatabase" {
  allocated_storage    = 20
  identifier           = "dbinstance"
  storage_type         = "gp2"
  engine               = "mysql"
  engine_version       = "5.7.30"
  instance_class       = "db.t2.micro"
  name                 = "Abhidb"
  username             = "Abhi"
  password             = "redhatabc"
  parameter_group_name = "default.mysql5.7"
  publicly_accessible = true
  skip_final_snapshot  = true
  iam_database_authentication_enabled = true
  
  tags = {
    Name = "AbhiSQLDB"
  }
}


output "ip" {
    value = "${aws_db_instance.abhidatabase.address}"
}

wp.tf

wf.tf

Wordpress Application ‘s DeploymenT will be Created In Kubernetes (Minikube) and also it will have 3 replicas and then we will get url to get the wordpress dashboard .

将在Kubernetes(Minikube)中创建Wordpress应用程序的DeploymenT,它还将具有3个副本,然后我们将获得url以获取wordpress仪表板。

Image for post
provider "kubernetes" {
    config_context_cluster   = "minikube"
}
resource "kubernetes_deployment" "abhiwp" {
  metadata {
    name = "wordpress"
  }
  spec {
    replicas = 3    
    selector{
    match_labels = {
      env = "Development"
      dc = "IN"
      App = "wordpress"
    }
    match_expressions {
      key = "env"
      operator = "In"
      values = ["Development" , "wordpress"]
    }
  }
   template {
        metadata {
         labels = {
      env = "Development"
      dc = "IN"
      App = "wordpress"
    }
        }




      spec {
        container {
          image = "wordpress"
         // image = "wordpress:4.8-apache"
          name  = "abhiwordpress"
        }
      }
    }
}
}
resource "kubernetes_service" "abhiwplb" {
  metadata {
    name = "loadbalancer"
  }
  spec {
    selector = {
      App = kubernetes_deployment.abhiwp.spec.0.template.0.metadata[0].labels.App
    }
    port {
      node_port   = 30100 
      port        = 80
      target_port = 80
    }
    type = "NodePort"
} 
}
terraform init
Image for post
terraform validate
Image for post
terraform plan
Image for post
terraform apply --auto-approve
Image for post

It will print url for getting wordpress dashboard and rdb ip so that we can connect the wordpress and rdb without going to aws .

它将打印用于获取wordpress仪表板和rdb ip的url,这样我们就可以连接wordpress和rdb而不用aws了。

Image for post

Now we can see that our Amazon RDS is created and now we are going to use in our wordpress application launched by terraform on the top of minikube u can see the url in above image for getting wordpress dashboard

现在我们可以看到已经创建了Amazon RDS,现在将在minikube顶部由terraform启动的wordpress应用程序中使用它,您可以在上图中看到url以获取wordpress仪表板

Image for post
Image for post
# paste this url in browserhttp://192.168.99.100:30100
Image for post
Image for post

Giving our database details ..

提供我们的数据库详细信息..

Image for post
Image for post
Image for post

Finally Here is Our Wordpress Application Launched on Minikube and having backend connectivity means database from Amazon RDS .

最后,这是我们在Minikube上启动的Wordpress应用程序,它具有后端连接功能,意味着来自Amazon RDS的数据库。

Image for post

Same EnvironmenT that we created in above steps can be destroyed in single command i.e.

我们在上述步骤中创建的相同环境可以在单个命令中销毁,即

terraform destroy --auto-approve

All The Code yOu can Find On My GitHub Repo

您可以在我的GitHub存储库上找到所有的代码

For furthur queries or suggestion’s feel free to ConnecT with me On Linkedin .

如有任何疑问或建议,随时可以在Linkedin上与我联系

THank yOu EveryOne For Reading ..!!

谢谢大家阅读 .. !!

翻译自: https://medium.com/swlh/aws-rds-terraform-kubernetes-wordpress-92e1fe25bb1

aws terraform

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值