jenkins + k8s + lnp
前提条件:
K8S 已部署好,traefik也部署完成
K8S 集群上都挂载NFS盘,防止jenkins挂掉后配置消失
基础镜像使用 lnp,PHP 5.6.31 nginx/1.8.1
基础镜像下载地址:docker pull liuyusheng/alpine-lnp:v1
docker私有仓库
[root@master jenkis]# cat jenkins-deployment.yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: jenkins
spec:
replicas: 1
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 2
maxUnavailable: 0
template:
metadata:
labels:
app: jenkins-last
spec:
nodeSelector:
jenkins: jenkins
containers:
- name: jenkins
image: jenkins:alpine
imagePullPolicy: IfNotPresent
ports:
- containerPort: 8080
name: web
protocol: TCP
volumeMounts:
- name: jenkinshome
mountPath: /var/jenkins_home
volumes:
- name: jenkinshome
nfs:
server: 192.168.0.161
path: /data/jenkins ---
kind: Service
apiVersion: v1
metadata:
name: jenkins
spec:
ports:
- port: 8080
targetPort: 8080
name: web
- port: 50000
targetPort: 50000
name: agent
selector:
app: jenkins-last
jenkins-ingress.yaml apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: traefik-ingress
namespace: default
spec:
rules:
- host: my.jenkins.com
http:
paths:
- path: /
backend:
serviceName: jenkins
servicePort: 8080
启动安装jenkins
kubectl create -f .
traefik 上可以查看
配置好SSH KEY 连接,这里不做配置SSH-KEY 操作
jenkins SERVER="192.168.0.153"
USER="root"
PORT="22"
GROUP_NAME="lin_lang"
JOB_NAME="fabaoguo"
DST_PATH="/data/tmp/"
HOME_DIR="/var/jenkins_home"
FILE_NAME=${JOB_NAME}.tar.gz DOCKER_REG="192.168.0.153:5000"
NGINX_CONF="www.${JOB_NAME}.com.conf"
BASE_IMG="alpine:v5"
#BUILD_NUM="v1" WWW_NAME="www.fabaoguo.com" BUILD_NUM=`date +%F-%H-%M-%S` #init
/usr/bin/test -d ${HOME_DIR}/releaseDir || /bin/mkdir -p ${HOME_DIR}/releaseDir /bin/tar -zcf ${HOME_DIR}/releaseDir/${FILE_NAME} --exclude=.svn --exclude releaseDir * \cp ${HOME_DIR}/scripts/www.example.com.conf ${HOME_DIR}/scripts/${NGINX_CONF}
sh ${HOME_DIR}/scripts/replace.sh ${HOME_DIR}/scripts/${NGINX_CONF} ${JOB_NAME} #deploy
/usr/bin/scp ${HOME_DIR}/releaseDir/${FILE_NAME} ${USER}@${SERVER}:${DST_PATH};
/usr/bin/scp ${HOME_DIR}/scripts/www.${JOB_NAME}.com.conf ${USER}@${SERVER}:${DST_PATH} /usr/bin/ssh -p ${PORT} ${USER}@${SERVER} "sh /data/scripts/build_lnp.sh ${FILE_NAME} ${NGINX_CONF} ${BASE_IMG} ${DOCKER_REG}/${JOB_NAME} ${BUILD_NUM}"; /usr/bin/ssh -p ${PORT} ${USER}@${SERVER} "sh /data/scripts/start_app.sh ${WWW_NAME} ${JOB_NAME} ${JOB_NAME} ${BUILD_NUM} ${JOB_NAME}.yaml" rm -f ${HOME_DIR}/releaseDir/${FILE_NAME}
rm -f ${HOME_DIR}/scripts/www.${JOB_NAME}.com.conf
192.168.0.153服务器上
[root@master scripts]# cat build_lnp.sh
#!/bin/bash
APP_NAME=$1
NGINX_CONF=$2
BASE_IMG=$3
FINISH_IMG=$4
BUILD_NUM=$5 test -d /data/tmp || mkdir /data/tmp -p if [ ! -n "$1" ] || [ ! -n "$2" ] || [ ! -n "$3" ] || [ ! -n "$4" ] || [ ! -n "$5" ] ;then
echo "build error,please input vars"
exit 1
else
ADD_FILE="ADD ${APP_NAME} /opt/www/"
ADD_TWO="ADD ${NGINX_CONF} /etc/nginx/conf.d/"
cp /data/build/Dockerfile_template /data/tmp/Dockerfile
sed -i "s#BASE_IMG#$BASE_IMG#" /data/tmp/Dockerfile
sed -i "s#ADD_FILE#$ADD_FILE#" /data/tmp/Dockerfile
sed -i "s#ADD_TWO#$ADD_TWO#" /data/tmp/Dockerfile
docker build --no-cache=true -t ${FINISH_IMG}:${BUILD_NUM} /data/tmp/
docker push ${FINISH_IMG}:${BUILD_NUM}
echo "build img is ${FINISH_IMG}:${BUILD_NUM}" fi
rm -rf /data/tmp/*
DOCKERFILE 模板
[root@master build]# cat Dockerfile_template
FROM BASE_IMG
MAINTAINER netop
ENV REFRESHED_AT 2017-11-09
ADD_FILE
ADD_TWO
创建K8S pod
[root@master scripts]# cat start_app.sh
#!/bin/sh WWW_NAME=$1
APP_NAME=$2
FINISH_IMG=$3
BUILD_NUM=$4 APP_DIR="/data/scripts"
APP_YAML="$5" if [ ! -n "$1" ] || [ ! -n "$2" ] || [ ! -n "$3" ] || [ ! -n "$4" ] || [ ! -n "$5" ];then
echo "build error,please input vars"
else
\cp $APP_DIR/deploy/example-app.yaml $APP_DIR/app/$APP_YAML
sed -i s"/example/${APP_NAME}/g" ${APP_DIR}/app/${APP_YAML}
sed -i s"/myimages/"${FINISH_IMG}"/g" ${APP_DIR}/app/${APP_YAML}
sed -i s"/build_num/${BUILD_NUM}/g" ${APP_DIR}/app/${APP_YAML}
sed -i s"/www.host.com/${WWW_NAME}/g" ${APP_DIR}/app/${APP_YAML} fi kubectl apply -f $APP_DIR/app/$APP_YAML --record
k8s APP yaml模板
[root@master scripts]# cat deploy/example-app.yaml
apiVersion: v1
kind: Service
metadata:
name: alpine-example
spec:
ports:
- port: 80
targetPort: 80
selector:
app: alpine-example
---
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: alpine-example
spec:
replicas: 1
minReadySeconds: 60
strategy:
rollingUpdate:
maxSurge: 50%
template:
metadata:
labels:
app: alpine-example
spec:
containers:
- name: alpine-example
image: 192.168.0.153:5000/myimages:build_num
#imagePullPolicy: IfNotPresent
imagePullPolicy: Always
ports:
- containerPort: 80
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: alpine-example
spec:
rules:
- host: www.host.com
http:
paths:
- path: /
backend:
serviceName: alpine-example
servicePort: 80
[root@master two]# kubectl get po -o wide
NAME READY STATUS RESTARTS AGE IP NODE
alpine-fabaoguo-3144943877-l9l8j 1/1 Running 0 22m 10.254.97.131 master
Traefik 上查看
jenkins + k8s + lnp的更多相关文章
- jenkins+k8s部署
1. jenkins配置部署,从git或者svn等拉取代码,编制打包,在博客的jenkins那块有具体的讲解 2. 将打好的包war/java包拷贝到k8s-Master,或者在jenkins上也行, ...
- Jenkins Kubernetes Slave 调度效率优化小记
Jenkins K8S Slave 调度效率优化 by yue994488@126.com 使用kubernetes为测试工具Gatling进行大规模压测,压测期间发现Jenkins调度压测实例较慢, ...
- .Net Core2.1 秒杀项目一步步实现CI/CD(Centos7.2)系列一:k8s高可用集群搭建总结以及部署API到k8s
前言:本系列博客又更新了,是博主研究很长时间,亲自动手实践过后的心得,k8s集群是购买了5台阿里云服务器部署的,这个集群差不多搞了一周时间,关于k8s的知识点,我也是刚入门,这方面的知识建议参考博客园 ...
- 实现CI/CDk8s高可用集群搭建总结以及部署API到k8s
实现CI/CD(Centos7.2)系列二:k8s高可用集群搭建总结以及部署API到k8s 前言:本系列博客又更新了,是博主研究很长时间,亲自动手实践过后的心得,k8s集群是购买了5台阿里云服务器部署 ...
- k8s~helm镜像版本永远不要用latest
对于容器编排工具k8s来说,你可以使用它规定的yaml格式的脚本,使用客户端kubectl来与k8s进行通讯,将你定义好的yaml部署脚本应用到k8s集群上,而这对yaml脚本一般来说都是很像的,就是 ...
- Kubernetes笔记(二):了解k8s的基本组件与概念
前文 Kubernetes笔记(一):十分钟部署一套K8s环境 介绍了如何快速搭建一个k8s系统.为了继续使用k8s来部署我们的应用,需要先对k8s中的一些基本组件与概念有个了解. Kubernete ...
- k8s实验操作记录文档
k8s实验操作记录文档,仅供学习参考! 文档以实验操作的过程及内容为主进行记录,涉及少量的介绍性文字(来自网络开源). 仅汇总主题所有链接,详细内容查看需要切换到相关链接.https://github ...
- 自己编写k8s
## 基于Docker和Kubernetes的企业级DevOps实践训练营 ### 课程准备 1. 离线镜像包 百度:https://pan.baidu.com/s/1N1AYGCYftYGn6L0Q ...
- docker | jenkins 实现自动化部署项目,后端躺着把运维的钱挣了!(上)
前言 背景 最近在帮学校导师写项目,团队有4个人,项目前后端分离.如果是选择瀑布式开发:(在约定好接口的情况下)A.B同学写前端,C.D同学写后端,然后约定一个时间统一联调,最后将项目交付安装到客户机 ...
随机推荐
- spark报错处理
Spark报错处理 1.问题:org.apache.spark.SparkException: Exception thrown in awaitResult 分析:出现这个情况的原因是spark启动 ...
- Ruby语言学习系列--String 类函数
函数名称 说明 示例 * 将字符串拷贝N次 “ha”*4 >> “hahahaha” + << concat 连接字符串 “yes” + “no” >& ...
- SpringMVC源码阅读:Controller中参数解析
1.前言 SpringMVC是目前J2EE平台的主流Web框架,不熟悉的园友可以看SpringMVC源码阅读入门,它交代了SpringMVC的基础知识和源码阅读的技巧 本文将通过源码(基于Spring ...
- js jq封装ajax方法
json文本格式 { "userInfo":[ {name:"admin",password:"123"}, {name:"adm ...
- readtimeout
请求头去掉content-length,未找到明确原因.
- Ionic3 UI组件之 ImagePicker
ImagePicker插件实现设备上的多个图像选择的功能. 组件特性: 统一选择界面,避免不同设备选择界面不一样的问题: 支持多选,并且可以设置最多选择的张数: 选择数量超出设置时会提示: Camer ...
- CSS3文本属性
text-shadow(文本阴影) <h1>我有文字阴影</h1> h1{ color:#ffff00; text-shadow:1px 2px 2px #000000; } ...
- Python逐行读取文件内容
更详细的文件按行读取操作可以参考:http://www.cnblogs.com/xuxn/archive/2011/07/27/read-a-file-with-python.html 一行一行得从文 ...
- Hackerrank GCD Product(莫比乌斯反演)
题意 题目链接 Sol 一道咕咕咕了好长时间的题 题解可以看这里 #include<bits/stdc++.h> #define LL long long using namespace ...
- ORA-00054 资源正忙
现象: 执行update.truncate提示 ORA-00054: resource busy and acquire with NOWAIT specified. 解决方法: 因为系统是RAC系统 ...