我们专注攀枝花网站设计 攀枝花网站制作 攀枝花网站建设
成都网站建设公司服务热线:400-028-6601

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

基于jenkins的k8sci/cd实例

K8S ci/cd三剑客:jenkinsfile、dockerfile、k8s.yaml
k8s的ci/cd实例
jenkins+jenkinsfile+dockerfile+k8s.yaml
1、dockerfile 实例
FROM harbor.k8s.site/library/jdk/jre:1.8-apline
ENV TZ=Asia/Shanghai
VOLUME /tmp
ADD build/libs/*.jar /app/app.jar
RUN mkdir /logs/ && echo 'java ${JVMSIZE} ${EUREKA} ${LOGPATH} ${APOLLO} -jar app.jar' > /usr/bin/run.sh;chmod a+x /usr/bin/run.sh
WORKDIR /app/
CMD run.sh

成都创新互联主要从事网站设计制作、成都网站设计、网页设计、企业做网站、公司建网站等业务。立足成都服务武乡,10年网站建设经验,价格优惠、服务专业,欢迎来电咨询建站服务:028-86922220

2、k8s.yaml 实例
apiVersion: apps/v1beta2
kind: Deployment
metadata:
name: yryd-client
namespace: default
labels:
k8s-app: yryd-client

spec:
replicas: 1
revisionHistoryLimit: 1
#滚动升级时70s后认为该pod就绪
minReadySeconds: 70
strategy:
##由于replicas为3,则整个升级,pod个数在2-4个之间
rollingUpdate:
#滚动升级时会先启动1个pod
maxSurge: 1
#滚动升级时允许的最大Unavailable的pod个数
maxUnavailable: 1
selector:
matchLabels:
k8s-app: yryd-client
template:
metadata:
labels:
k8s-app: yryd-client
spec:
containers:

  • name: yryd-client
    image: harbor.k8s..site/yryd/yryd-client:build-
    ports:
    #容器的端口
    • containerPort: 5001
      name: yryd-client
      protocol: TCP
      env:
    • name: JVMSIZE
      value: -Xms1G -Xmx1G
    • name: LOGPATH
      value: -Dlogging.path=/logs/yryd/yryd-client/

      apiVersion: v1
      kind: Service
      metadata:
      name: yryd-client
      namespace: default
      labels:
      k8s-app: yryd-client
      spec:
      ports:
      #集群IP的端口

      • port: 5001
        name: yryd-client
        protocol: TCP
        #容器的端口
        targetPort: 5001
        selector:
        k8s-app: yryd-client

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: yryd-client
namespace: default
spec:
rules:

  • host: yryd-client.k8s..site
    http:
    paths:
    • backend:
      serviceName: yryd-client
      servicePort: 5001

3、jenkinsfile实例

pipeline {
agent {
label 'master'
}
parameters {
string(name: "branch", defaultValue: "master", description: "code branch")
extendedChoice(
defaultValue: '',
description: '选择发布模块',
multiSelectDelimiter: ',',
name: 'module',
quoteValue: false,
saveJSONParameterToFile: false,
type: 'PT_CHECKBOX',
value:'yryd-client',
visibleItemCount: 10)
}
options {
skipDefaultCheckout(true)
buildDiscarder(logRotator(daysToKeepStr: '5', numToKeepStr: '8'))
}
stages{
stage('get code'){
steps{
git branch: '$branch', credentialsId: 'dd93cf17-ab6c-48e4-9aca-b063d05a031b', url: 'http://git.bqjr.club/MMT-YRYD/mmt-yryd.git'
}
}
stage('yryd-client'){
when {
expression { return "$params.module".contains('yryd-client')}
}
steps {
sh '''
imageName="harbor.k8s.site/yryd/yryd-client:build-${BUILD_NUMBER}"
cd mmt-yryd-client-service/
/opt/software/gradle-4.8/bin/gradle clean excludedev build -x test
docker build -t ${imageName} .
docker push ${imageName}
docker rmi ${imageName}
sed -i "s//${BUILD_NUMBER}/g" k8s.yaml
kubectl apply -f k8s.yaml --record
'''
}
}
}
}


新闻名称:基于jenkins的k8sci/cd实例
浏览路径:http://mswzjz.cn/article/jojsic.html

其他资讯