Jenkins+Kubernetes CI/CD

Jenkins + Kubernetes CI/CD
步骤如下

  1. 安装Kubernetes集群
  2. 开通容器镜像服务,创建镜像仓库,如ycdocker/demo
  3. 在集群外的ECS上安装Jenkins
  4. 在Jenkins所在ECS安装kubectl,用以访问Kubernetes集群

    wget https://dl.k8s.io/v1.10.6/kubernetes-client-linux-amd64.tar.gz
    tar -xvf kubernetes-client-linux-amd64.tar.gz
    cd kubernetes/client/bin
    chmod +x ./kubectl
    sudo mv ./kubectl /usr/local/bin/kubectl
    mkdir /root/.kube
    vi /root/.kube/config
  5. 安装Docker

    
    # step 1: 安装必要的一些系统工具
    sudo apt-get update
    sudo apt-get -y install apt-transport-https ca-certificates curl software-properties-common
    # step 2: 安装GPG证书
    curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
    # Step 3: 写入软件源信息
    sudo add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
    # Step 4: 更新并安装 Docker-CE
    sudo apt-get -y update
    sudo apt-get -y install docker-ce
  6. 安装maven apt-get install maven -y
  7. 选择Spring Boot Demo项目,Dockerfile放根目录

    FROM openjdk:8-jdk-alpine
    VOLUME /tmp
    ARG JAR_FILE
    COPY ${JAR_FILE} app.jar
    ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
  8. 上传代码到Git
  9. 登陆Jenkins,创建free style项目
  10. 配置Jenkins从Git取代码
  11. 添加构建步骤,Shell脚本如下
mvn clean package
docker build --build-arg JAR_FILE=target/gs-spring-boot-docker-0.1.0.jar -t registry.cn-beijing.aliyuncs.com/ycdocker/demo:$BUILD_NUMBER .
docker login --username=***** --password=***** registry.cn-beijing.aliyuncs.com
docker push registry.cn-beijing.aliyuncs.com/ycdocker/demo:$BUILD_NUMBER
kubectl set image deployment/demo demo=registry.cn-beijing.aliyuncs.com/ycdocker/demo:$BUILD_NUMBER
  1. 修改代码测试效果

你可能感兴趣的:(Jenkins+Kubernetes CI/CD)