k8s cicd (jenkins + gitops)

ci:jenkins  cd:gitops  image repository:harbor

1jenkinsfile配置示例

 environment {
     K8S_CONFIG = credentials('jenkins-k8s-config')
     GIT_TAG = "1.0.0-SNAPSHOT"
 }
 parameters {
     string(name: 'HARBOR_HOST', defaultValue: '10.1.53.65:5000', description: 'harbor仓库地址')
     string(name: 'DOCKER_IMAGE', defaultValue: 'aosom-pop/stock', description: 'docker镜像名')
     string(name: 'APP_NAME', defaultValue: 'stock', description: 'k8s中标签名')
     string(name: 'K8S_NAMESPACE', defaultValue: 'dev', description: 'k8s的namespace名称')
 }

 def label = "jenkins2-jenkins-slave"
 podTemplate(label: label, cloud: 'kubernetes') {
 node ('jenkins2-jenkins-slave'){
   stage('maven build'){
      container('jnlp') {
                 checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'gitsshkey', url: 'ssh://[email protected]:8899/aosom/pop_products.git']]])
                 sh "docker login 10.1.53.65:5000 -u admin -p Harbor12345 "
                 sh 'mvn clean package -Dfile.encoding=UTF-8 -DskipTests=true'

     }
   }
   
 }
}

 

2jenkins slave使用自定义镜像

10.1.53.65:5000/aosom-pop/jnlp-slave:1.0.0

3jnlp-slave:1.0.0 dockerfile

FROM jenkins/jnlp-slave:3.27-1

MAINTAINER HXP

USER root
#ADD apache-maven-3.6.2-bin.tar.gz /opt/
#RUN echo -e "\n">>~/.bash_profile && echo -e "export M2_HOME=/opt/apache-maven-3.6.2\n" >> ~/.bash_profile \
# && echo "export PATH=$PATH:$M2_HOME/bin">>~/.bash_profile && . ~/.bash_profile && ln -s /opt/apache-maven-3.6.2/bin/mvn /usr/bin/mvn
RUN apt-get update && apt-get -y install maven
ADD config.json /root/.docker/
ADD config /root/.kube/
ADD kubectl /usr/bin/
RUN chmod 777 /usr/bin/kubectl

USER root

ENTRYPOINT ["jenkins-slave"]

 

3jenkins部署方式

/var/jenkins_home 挂在到pvc

采用helm方式部署

4gitops部署方式

采用helm方式部署flux

你可能感兴趣的:(kubernetes)