kubernetes实现ci/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

目前创新互联公司已为上1000家的企业提供了网站建设、域名、虚拟主机绵阳服务器托管、企业网站设计、阳春网站维护等服务,公司将坚持客户导向、应用为本的策略,正道将秉承"和谐、参与、激情"的文化,与客户和合作伙伴齐心协力一起成长,共同发展。

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         
'''
}      
}    
}
}

另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


文章名称:kubernetes实现ci/cd-创新互联
当前路径:http://csdahua.cn/article/dddeop.html
扫二维码与项目经理沟通

我们在微信上24小时期待你的声音

解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流