溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

kubernetes實(shí)現(xiàn)ci/cd

發(fā)布時(shí)間:2020-05-27 15:16:01 來(lái)源:億速云 閱讀:1145 作者:鴿子 欄目:系統(tǒng)運(yùn)維

K8S ci/cd三劍客:jenkinsfile、dockerfile、k8s.yaml
k8s的ci/cd實(shí)例
jenkins+jenkinsfile+dockerfile+k8s.yaml
1、dockerfile 實(shí)例
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

2、k8s.yaml 實(shí)例
apiVersion: apps/v1beta2
kind: Deployment
metadata:
name: yryd-client
namespace: default
labels:
k8s-app: yryd-client

spec:
replicas: 1
revisionHistoryLimit: 1
#滾動(dòng)升級(jí)時(shí)70s后認(rèn)為該pod就緒
minReadySeconds: 70
strategy:
##由于replicas為3,則整個(gè)升級(jí),pod個(gè)數(shù)在2-4個(gè)之間
rollingUpdate:
#滾動(dòng)升級(jí)時(shí)會(huì)先啟動(dòng)1個(gè)pod    
maxSurge: 1
#滾動(dòng)升級(jí)時(shí)允許的最大Unavailable的pod個(gè)數(shù)
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-<BUILD_TAG>
    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實(shí)例

pipeline {
agent {
label 'master'
}
parameters {
string(name: "branch", defaultValue: "master", description: "code branch")      
extendedChoice(
defaultValue: '',
description: '選擇發(fā)布模塊',
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_TAG>/${BUILD_NUMBER}/g" k8s.yaml
kubectl  apply -f k8s.yaml --record                
'''
}          
}      
}
}

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI