Devops Solution for PHP Applications Running on Kubernetes

Source: Internet
Author: User
Keywords devops solutions and services php devops devops docker kubernetes
1 Overview
The php application runs on kubernetes. It is not very convenient to manually deploy a new version each time it is released. This requires the establishment of a devops solution for rapid deployment of php applications. This program uses jenkins as a pipeline tool. In this program, svn is used as the code base. Developers submit code through svn. For rapid deployment, first pull the code from svn, then use docker to package the image, and use nexus to build a private warehouse, manage the image in the private warehouse, and finally devops pull the image from the private warehouse and deploy it on kubernetes. In addition, you can use the program as a reference to promote it to other applications that do not require code dependencies and do not require compilation.

2. Installation and deployment
In this solution, svn and nexus are both applications outside the container cloud, and docker is deployed on the physical machine, which will not be repeated here.

This section focuses on the deployment of jenkins on kubernetes. This article uses the official image of jenkins as the base image of our deployment image. Docker is not installed in the official image. We need to install docker in the image. We also need to use some plug-ins, which are installed together in the image.

Download https://download.docker.com/linux/debian/dists/stretch/pool/stable/amd64/docker-ce_18.06.0~ce~3-0~debian_amd64.deb and rename it to docker-ce.deb. Create a new image according to the following Dockerfile file.

FROM jenkins/jenkins:lts

USER root

RUN apt-get update && apt-get install -y iptables && apt-get install -y libdevmapper1.02.1 && apt-get install -y libltdl7 && apt-get install -y libseccomp2

ADD docker-ce.deb /tmp/

RUN dpkg -i /tmp/docker-ce.deb && rm -rf /tmp/docker-ce.deb

RUN /usr/local/bin/install-plugins.sh kubernetes-cd:0.2.3 subversion:2.11.1 docker-build-publish:1.3.2

USER Jenkins

After that, we can use this image to deploy jenkins.

#————————Define agency service————————-

apiVersion: v1

kind: Service

metadata:

name: jenkins-php

spec:

type: NodePort

ports:

# Port mapping port

– Port: 8080

targetPort: 8080

name: pipeline8080

selector:

app: jenkins-php

—

 

# ————————Define the deployment of jenkins —————————

apiVersion: apps/v1

kind: Deployment

metadata:

name: jenkins-php

spec:

selector:

matchLabels:

app: jenkins-php

revisionHistoryLimit: 2

template:

metadata:

labels:

app: jenkins-php

spec:

containers:

# Application mirror

– Image:phpdevops:v1.0 #Jenkins image based on official image

name: jenkins-php

imagePullPolicy: IfNotPresent

# Internal port of the application

ports:

– ContainerPort: 8080

name: pipeline8080

volumeMounts:

# jenkins-devops persistence

– Name: pipeline-persistent

mountPath: /var/jenkins_home

volumes:

# Use nfs internet storage

– Name: pipeline-persistent

nfs:

server: 192.168.8.150

path: /k8s-nfs/jenkins-php


3. Devops configuration
3.1. Docker configuration
In a physical machine where docker is installed, add the following content to the /etc/docker/daemon.json file. Among them, 10.0.32.148:1008 is the address and port of the mirror warehouse, and tcp://0.0.0.0:4243 is the address and port exposed to the outside world.

{

"Hosts":["tcp://0.0.0.0:4243","unix:///var/run/docker.sock"],

"Insecure-registries":["10.0.32.148:1008"]

}

And restart the docker service by executing the following command:
$ systemctl daemon-reload

$ systemctl restart docker


3.2. Jenkins configuration

Create a task named php.

Set svn information.
Repository URL: The address of svn.
Credentials: svn username and password can be added temporarily.

Set the information for building an image, uploading an image, and deploying it.

Repository Name: Image name
Tag: Mirror version
Docker Host URI: address and port of docker service;
Docker registry URL: the address of the docker mirror warehouse;
Registry credentials: User name and password of the mirror repository.
Kubernetes Cluster Credentials: Kubernetes cluster authentication method;
Path: the address of the kubeconfig file;
Config Files: yaml configuration files for deploying applications in the cluster.

After the configuration is completed, the Dockerfile to build the image and the yaml to deploy the application need to be placed in the root directory of the svn project and managed by svn.

4. Build
After the configuration is completed, the project can be built with one-click operation. By immediately building a one-click operation, Jenkins will complete all the work of pulling the code, packaging the image, uploading the image, and deploying.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.