devops 项目经理_devops项目

devops 项目经理

问题陈述:(Problem Statement:)

  • Deploy Webserver using the best Principles, Tools, Techniques of DevOps Culture.

    使用DevOps Culture的最佳原则,工具和技术部署Web服务器。

解决方案的简要说明: (Brief Explanation of Solution:)

Here I am using Ansible for the configuration management system, Jenkins for CI/CD, Jenkins with Multi-Node Cluster, Build Jobs using DSL Code of Jenkins, for production I am using one of the famous services of AWS,i ,e AWS EKS(Elastic k8s Service).

在这里,我将Ansible用于配置管理系统,将Jenkins用于CI / CD ,将Jenkins用于多节点集群,使用Jenkins的DSL代码构建作业,用于生产,我正在使用AWS的一项著名服务,即AWS EKS (弹性k8s服务)。

先决条件: (Prerequisite:)

  • Linux OS(Redhat, Centos).

    Linux操作系统(Redhat,Centos)。
  • Have an AWS account.

    有一个AWS账户。
  • Created IAM users with AdministratorAccess Permission.

    已创建具有AdministratorAccess权限的IAM用户。
  • AWS CLIv2 configured in Linux with IAM user.

    在Linux中使用IAM用户配置了AWS CLIv2。
  • kubectl, eksctl configured in Linux.

    kubectl,在Linux中配置的eksctl。
  • Ansible, Git installed in Linux.

    Ansible,在Linux中安装了Git。

步骤1)开发网站代码: (Step-1)Developing website Code:)

Image for post
The developer develops the code
开发人员开发代码
Image for post
Code pushed in Github
在Github中推送代码

Note: Here one point, here we need one Dockerfile for building our docker iso for a webserver.

注意:这里有一点,这里我们需要一个Dockerfile来为网络服务器构建docker iso。

Image for post
Dockerfile
Docker文件

Explanation of Docker: Here my Dockerfile copy all the code in the respective image for building iso for our webserver.

Docker的说明:在这里,我的Dockerfile复制了各自映像中的所有代码,用于为我们的Web服务器构建iso。

现在,DevOpsTeam的时机已经到来,可以使用最佳实践,工具,技术等来部署此代码。 (Now The time for DevOpsTeam has come to deploy this code using best practices, tools, techniques, etc.)

步骤2)准备好安装程序。 (Step-2)Getting setup ready.)

  • Here I am using Jenkins on top of docker, for setting up Jenkins , and we have to first install docker in OS, So for the Configuration Management System, I am using Ansible-Roles.

    在这里,我在Docker之上使用Jenkins来设置Jenkins,我们必须首先在OS中安装docker ,因此对于配置管理系统,我正在使用Ansible-Roles。

Image for post
Ansible-config file
Ansible-config文件
  • Here my ansible roles path and all the things are configured.

    在这里,我的角色角色路径和所有事物都已配置。
Image for post
Ansible-roles
Ansible角色
Image for post
Ansible-Role Code.
角色扮演代码。
  • To run this code we have to create one playbook and use this role in that playbook.

    要运行此代码,我们必须创建一个剧本并在该剧本中使用此角色。
Image for post
Ansible-Playbook
Ansible剧本
  • Code of Ansible-Playbook:

    Ansible-Playbook的代码:
- hosts: localhost
roles:
- docker_rehl8
  • to run this playbook type:

    运行此剧本类型:
ansible-playbook FILE_NAME.yml

角色和剧本的解释:在这里,我首先使用yum_repository模块为docker配置yum,此后,我使用命令模块安装docker,当所有安装完成后,我已经创建并拖入hub.docker.com詹金斯iso。 只有我需要拉入操作系统,因此我使用了一个模块从hub.docker.com中拉出我的Jenkins iso (Explanation of Roles and playbook: Here I and first configuring yum using the yum_repository module for docker, and after that, I install docker using the command module, and when all installation completed, I have already created and pull into my hub.docker.com of Jenkins iso. Only just I need to pull in my os, so I used a module for pulling my Jenkins iso from hub.docker.com)

Dockerfile of Jenkins:

Jenkins的Dockerfile:

FROM centos
RUN dnf install wget -y
RUN wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins.io/redhat-stable/jenkins.repo
RUN rpm --import http://pkg.jenkins.io/redhat-stable/jenkins.io.key
RUN dnf install java-11-openjdk.x86_64 jenkins -y
RUN dnf install -y openssh-server
RUN dnf install net-tools -y
RUN dnf install git -y
RUN dnf install httpd -y
RUN dnf install which -y
RUN dnf install python36 -y
RUN pip3 install ansible
RUN echo "jenkins ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
RUN echo "java -jar /usr/lib/jenkins/jenkins.war &" >> /root/.bashrc
RUN bash

输出: (Output:)

Image for post
Jenkins iso
詹金斯iso
Image for post
docker installed by ansible-roles
由ansible-roles安装的docker
Image for post
Jenkins-iso pulled by ansible-roles
詹金斯-iso被ansible-roles拉动

步骤3)Jenkins设置。(Step-3)Jenkins Setup.)

  • Only just we need to start Jenkins container, type:

    只需要启动Jenkins容器,输入:
docker run -it --name jenkins1 -p 8082:8080 -v /root/jenkinsdata/:/root/.jenkins rootritesh/jenkins:v1
  • Here they starting container and exposing port 8080 of Jenkins, for making data persistent I mount Jenkins location on /root/jenkinsdata.

    他们在这里启动容器并暴露Jenkins的端口8080,以使数据持久化,我将Jenkins位置安装在/ root / jenkinsdata上。
  • Now configuring Jenkins:

    现在配置Jenkins:
Image for post
  • Copy-paste the password from the terminal.

    从终端复制并粘贴密码。
Image for post
  • No need to install plugins right now, close it.

    无需立即安装插件,将其关闭。
Image for post
Jenkins is ready
詹金斯准备好了

步骤4)在Jenkins中安装插件。(Step-4)Installing plugins in Jenkins.)

  • Go to Manage Jenkins>Plugin Manager.

    转到管理詹金斯>插件管理器。
Image for post
  • install these plugin > GitHub, job DSL, pipeline.

    安装这些插件> GitHub,作业DSL,管道。
  • Click on install without restart

    单击安装而不重新启动
Image for post

步骤5)配置Jenkins(Step-5)Configure Jenkins)

  • Here I using Jenkins Multi-Node Cluster, For configuring it Goto configure> Node> New Node> Add a new Node.

    在这里,我使用Jenkins多节点集群,要对其进行配置,请转到配置>节点>新节点>添加新节点。
  • Here I am using two nodes one for Developer job building and another for DevOps team.

    在这里,我使用两个节点,一个用于开发人员工作,另一个用于DevOps团队。
  • Now in the AWS launch one ec2 and configure it:

    现在在AWS中启动一个ec2并进行配置:
$sudo su -- root
$yum install git -y
#yum remove java-1.7.0-openjdk -y
$yum install java-1.8.0 -y
$yum install docker
$docker login (type username and password)
$docker pull centos.
$docker pull rootritesh/webserver-php
  • We need this configuring for a dev job.

    我们需要为开发作业进行此配置。
Image for post
AWS ec2
AWS ec2
  • For the first Node, I am using AWS EC2.

    对于第一个节点,我正在使用AWS EC2。
Image for post
  • Give the credential > Select kind > SSH Username with private key > give username (ec2-user) > Private key > Add it

    提供凭据>选择种类>带有私钥的SSH用户名>给出用户名(ec2-user)>私钥>添加它
Image for post
  • Save it.

    保存。
  • The output of the AWS Node.

    AWS节点的输出。
Image for post
AWS node is Connected
AWS节点已连接
  • Second Node which my Base Os of Linux where all things are configured like=> AWS CLI, eksctl, etc.

    第二个节点,我Linux基本操作系统中配置了所有内容的=> AWS CLI,eksctl等。
Image for post
Linux node
Linux节点
  • For credentials of Base, OS Linux, Connect vi ssh >provide username and password

    对于Base,OS Linux的凭据,请连接vi ssh>提供用户名和密码
  • Save it.

    保存。
  • The output of the Linux Node.

    Linux节点的输出。
Image for post
Linux Node Connected Successfully
Linux节点连接成功
  • Now after that, we need to configure our Email Notification in Jenkins.

    现在,在此之后,我们需要在詹金斯中配置电子邮件通知。
  • When our Job fails Jenkins Automatically sends the email to the team.

    当我们的工作失败时,詹金斯自动将电子邮件发送给团队。
  • Go to Manage Jenkins > Configure System.

    转到管理Jenkins>配置系统。
  • At the bottom there option E-mail Notification.

    在底部,有电子邮件通知选项。
Image for post
E-mail Notification
电子邮件通知
  • It is working, test configured successfully.

    它正在工作,测试配置成功。

步骤5)詹金斯DSL作业 (Step-5)Jenkins DSL JOB)

  • Make one freestyle job name jobdsl.

    使一个自由式作业名称为jobdsl。
  • Configure it using the following groovy DSL code.

    使用以下常规DSL代码对其进行配置。
Image for post

码: (Code:)

job('devjob') {
scm {
github('rootritesh/DevOps_Project')
}
triggers{
scm("* * * * *")
}label('aws')steps {
shell('''
sudo su -- root
pwd
sudo docker build -t rootritesh/myproserver:v8 .
sudo docker push rootritesh/myproserver:v8''')}
}job('prod') {
label('kube')steps {
shell('''
wget https://raw.githubusercontent.com/rootritesh/AWS-EKS-TASK/master/cluster.yaml
eksctl create cluster -f cluster.yaml
sleep 5
kubectl get pods
if kubectl get deployments | grep myweb
then
echo "Webserver is running"
kubectl describe deployment myweb
else
kubectl create deployment myweb --image=rootritesh/myproserver:v8
kubectl scale deployment myweb --replicas=5
kubectl expose deployment myweb --port=80 --type=LoadBalancer
fi''')}
}job('status') {
label('kube')
triggers{
scm("* * * * *")
}steps {
shell('''
if kubectl get deployment | grep myweb
then
echo "Deployment is There"
else
exit 1
fi
''')
}
publishers {
mailer('rootritesh34@gmail.com', false)
}
}

Explanation: Here I am using Jenkins DSL Groovy language for configuring jobs.

说明:这里我使用Jenkins DSL Groovy语言来配置作业。

步骤6)配置Jenkins管道作业。 (Step-6) Configure Jenkins Pipeline Job.)

  • Make one Pipeline job name MYAL.

    使一个管道作业名称为MYAL。
  • Configure it, using the following code.

    使用以下代码对其进行配置。
Image for post
Jenkins Pipeline Job
詹金斯管道作业

码:(Code:)

pipeline {
agent anystages {
stage('Dev') {
steps {
echo 'building dev jobs'
build job: 'devjob'
}
}stage('Prod') {
steps {
echo 'building production world'
build job: 'prod'
}
}

stage('checking status') {
steps {
echo 'status'
build job: 'status'
}
}
}
}

Explanation: This Pipeline job is running one by one job which is configured

说明:该管道作业正在配置的一个作业中运行

步骤7)运行作业DSL(Step-7)Run Job DSL)

  • Goto jobdsl job and build it.

    转到jobdsl工作并进行构建。
Image for post
  • Build it.

    建立它。

Output of jobdsl

jobdsl的输出

Image for post
Job build
职位建立
  • Here our job build successfully

    在这里,我们的工作成功建立

The output of Jobs:

Jobs的输出:

Image for post
  • Here our jobs build successfully.

    在这里,我们的工作成功建立。
  • Name of jobs:

    工作名称:
  • $devjob.

    $ devjob。
  • $prod(Production)

    $ prod(生产)
  • $status.

    $状态。

步骤8)运行管道作业 (Step-8) Run the Pipeline Job)

  • Now go and build the MYAL pipeline job.

    现在开始构建MYAL管道作业。
Image for post
build it
建立它

The output of the Pipeline:

管道的输出:

Image for post
Pipeline console output
管道控制台输出

Jobdsl DSL Groovy代码说明:(Explanation of jobdsl DSL groovy Code:)

在这里,我要进行三项工作,一项用于devjob,第二项用于生产,第三项用于部署状态检查。 (Here I am making three jobs one for devjobs, second for production, third for status checking of deployment.)

devjob的解释: (Explanation of devjob:)

当devjob由管道构建时,它的作用是,首先将其连接到AWS的节点。在那里,他们下载开发人员代码以准备docker iso,从GitHub链接提供的Dockerfile中为生产环境构建docker iso。 在建立之后,他们将推送到hub.docker.com进行拉取。 (When the devjob build by the pipeline, what it does, first it connect to the Node of AWS On there they download the Developer Code prepare the docker iso, build it docker iso for the production world from Dockerfile provided by the GitHub link. After that building, they push to the hub.docker.com for pulling.)

devjob的输出: (Output of devjob:)

Image for post
AWS Ec2
AWS Ec2
  • Here our code has been downloaded successfully.

    在这里,我们的代码已成功下载。
Image for post
docker image
码头工人形象
  • Here our Docker image built successfully.

    在这里,我们的Docker镜像成功构建。
Image for post
  • Here our ISO has been pushed into hub.docker.com

    在这里,我们的ISO已被推送到hub.docker.com

产品说明: (Explanation of prod job:)

devjob prod作业运行后,首先将其连接到适用于我的AWS EKS(弹性K8s群集)设置Linux节点,然后从GitHub代码下载群集代码,在群集中,它使用竞价型实例,并创建EKS群集通过使用eksctl命令,在此集群设置之后,它将为我们的生产创建一个部署,它将创建一个部署名称myweb,并使用由devjob构建的映像,并且还会对其进行缩放,并且在这里访问我的网站我正在使用服务使用AWS Loadbalancer的EKS中的LoadBalancer。 (After the devjob prod job runs, first it connect to Linux Node for my AWS EKS(Elastic K8s Cluster) setup, it downloads the cluster code from the GitHub code, In the cluster, it is using spot instance, and it creates the EKS cluster by using eksctl command, after this cluster setup, it creates a deployment for our production, it creates one deployment name myweb and uses an image which is built by the devjob, it also scales it, and Here for accessing my Website I am using service LoadBalancer in EKS, which is using AWS Loadbalancer.)

产品作业的输出: (Output of prod job:)

Image for post
EKS cluster
EKS集群
  • Here EKS cluster is ready.

    至此,EKS集群已准备就绪。
Image for post
clusters
集群
  • Here our Nodegroup has been configured.

    此处,我们的节点组已配置。
Image for post
kubectl get deployments
kubectl进行部署
  • Here U can see my all deployments running fine.

    在这里,您可以看到我的所有部署运行正常。
Image for post
LoadBalancer
负载均衡器
  • AWS Loadbalancer created by the service of K8s, for accessing our Website.

    由K8s服务创建的AWS Loadbalancer,用于访问我们的网站。

状态作业说明: (Explanation of status job:)

这项工作继续进行,并检查该部署是否存在,如果没有,它将向相应团队发送电子邮件。 (this job goes and checks whether this deployment is there or not, if not it sends the email to the respective team.)

状态作业的输出: (Output of status job:)

Image for post
  • It is the test email send by Jenkins, it means our Jenkins E-mail job working fine.

    这是Jenkins发送的测试电子邮件,这意味着我们的Jenkins电子邮件工作正常。

最终输出。 (FINAL Output.)

  • Copy Loadbalancer DNS name into the browser for website output.

    将Loadbalancer DNS名称复制到浏览器中以进行网站输出。
Image for post
Website
网站
  • Here our Website comes, running on EKS cluster, using Loadbalancer.

    这是我们的网站,它使用Loadbalancer在EKS群集上运行。

注意:为了监视这些节点组,我们可以使用由AWS提供的监视服务,但是不建议在这里使用Prometheus和Grafana作为指标,而Splunk为日志。 要了解更多,我们还可以设置警报。 (Note: For monitoring these Node Groups We can use monitoring services provided by the AWS, but it is not recommended here we can use Prometheus and Grafana for metrics, and Splunk for logs. for more, we can also set alarms.)

Image for post
Image for post
Image for post

最终解释: (Final Explanation:)

Here I completed this project using END-TO-END Automation, for configuration management I use Ansible. My Devjob running on AWS EC2 using Jenkins multi Node Cluster, and my Production is running on one of the powerful services of AWS i,e AWS EKS provide the best resources, high availability, etc. and at last by status is checking whether my deployment is there or not, if not it sends the email to the teams.

在这里,我使用END-TO-END Automation完成了这个项目,使用Ansible进行配置管理。 我的Devjob使用Jenkins多节点集群AWS EC2上运行,我的Production在AWS的一项强大服务上运行,即AWS EKS提供了最佳资源,高可用性等,最后按状态检查我的部署是否是否存在,如果没有,它将向团队发送电子邮件

Github链接: (Github Link:)

翻译自: https://medium.com/@rootritesh/devops-project-f17715ca132b

devops 项目经理

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值