Cloud Native 19 min read

Automate SpringBoot CI/CD with Jenkins, Docker, and Python on a Kubernetes Cluster

This guide walks through setting up a complete CI/CD pipeline for a SpringBoot micro‑services project using Jenkins, Docker, Harbor, GitLab, and Python scripts to build, package, and deploy containers onto a Kubernetes cluster, covering environment installation, configuration, and testing steps.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Automate SpringBoot CI/CD with Jenkins, Docker, and Python on a Kubernetes Cluster

This article demonstrates a CI/CD workflow centered on Jenkins, using Python to orchestrate the full release process of a SpringBoot project. The pipeline integrates Docker and the Kubernetes Python SDK to handle building, packaging, and deploying the application.

Installation Environment

First, install the required base components (JDK, Maven, Tomcat, Jenkins, GitLab, Docker, Harbor) on a three‑node Kubernetes cluster initialized with kubeadm.

JDK

tar xf jdk-8u212-linux-x64.tar.gz
mv jdk1.8.0_212/ /usr/local/jdk
cat >> /etc/profile <<EOF
export JAVA_HOME=/usr/local/jdk
export CLASSPATH=.:$JAVA_HOME/jre/lib/*:$JAVA_HOME/lib/*
export PATH=$PATH:$JAVA_HOME/bin
EOF
source /etc/profile
java -version

Maven

tar xf apache-maven-3.5.0-bin.tar.gz
mv apache-maven-3.5.0 /usr/local/maven
cat >> /etc/profile <<EOF
export MAVEN_HOME=/usr/local/maven
export PATH=$MAVEN_HOME/bin:$PATH
EOF
source /etc/profile
# Configure Alibaba Cloud mirror
vim /usr/local/maven/conf/settings.xml
# Add mirror configuration here
mvn -v

Tomcat

tar xf apache-tomcat-8.5.53.tar.gz
mv apache-tomcat-8.5.53 /usr/local/tomcat
cat > /usr/local/tomcat/conf/server.xml <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<Server port="8005" shutdown="SHUTDOWN">
  ... (standard Tomcat configuration) ...
  <Context path="" docBase="/data/jenkins/wwwroot" reloadable="true" />
</Server>
EOF

Jenkins

# Set Jenkins data directory
cat >> /etc/profile <<EOF
export JENKINS_HOME=/data/jenkins/data
EOF
source /etc/profile
mkdir -p /data/jenkins/{wwwroot,data}
unzip jenkins.war -d /data/jenkins/wwwroot
/usr/local/tomcat/bin/startup.sh

Install common Jenkins plugins: Locale, Git Parameter, Maven Integration, AnsiColor.

GitLab

wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-12.9.3-ce.0.el7.x86_64.rpm
yum install -y gitlab-ce-12.9.3-ce.0.el7.x86_64.rpm
# Edit /etc/gitlab/gitlab.rb to set external_url and SMTP settings
gitlab-ctl reconfigure

Docker

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -O /etc/yum.repos.d/docker.repo
yum install -y bash-completion docker-ce docker-compose
systemctl start docker
# Kernel bridge settings
cat >> /etc/sysctl.conf <<EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-arptables = 1
EOF
sysctl -p
# Docker registry mirror
cat >> /etc/docker/daemon.json <<EOF
{"registry-mirrors": ["https://owcyje1z.mirror.aliyuncs.com"]}
EOF
systemctl daemon-reload
systemctl restart docker

Harbor

tar xf harbor-offline-installer-v1.8.3.tgz
mv harbor /usr/local/harbor
cd /usr/local/harbor
# Edit harbor.yml for hostname, ports, admin password, etc.
./install.sh

Project Setup and Testing

Clone the sample SpringCloud repository and build the Eureka service.

git clone https://github.com/caichangen/SpringCloud.git
cd SpringCloud/eureka
mvn clean install -Dmaven.test.skip=true compile package spring-boot:repackage
java -jar target/eureka.jar &   # runs on port 6220
curl -sIL -w "%{http_code}
" -o /dev/null localhost:6220   # should return 200

Build Docker Image

cat > Dockerfile <<EOF
FROM gmaslowski/jdk
RUN mkdir -p /data/source
ADD eureka.jar /data/source
CMD ["/opt/jdk/bin/java","-jar","/data/source/eureka.jar"]
EXPOSE 6220/TCP
EOF
mkdir context && mv Dockerfile target/eureka.jar context/
cd context
docker build -t eureka:v1 .
docker run -it --rm -p 8888:6220 eureka:v1
curl -sIL -w "%{http_code}
" -o /dev/null localhost:8888   # should return 200

Push Code and Dockerfiles to GitLab

Create four GitLab projects (eureka, zuul, feign, ribbon) and push each component with its Dockerfile and README.

# Example for eureka
cd SpringCloud/eureka
git init
git remote add origin http://192.168.1.64/SpringCloud/eureka.git
git add .
git commit -m 'add code'
git push -u origin master
# Repeat for zuul, feign, ribbon with corresponding Dockerfiles

Jenkins Pipeline with Python

Configure a Jenkins job that pulls the code, builds the Maven project, creates a Docker image, and pushes it to Harbor using a Python script (eureka-ci.py). Install the Docker Python SDK and set Docker daemon to allow insecure registries.

# Install Docker SDK for Python
pip3 uninstall docker -y
pip3 install docker -i https://pypi.tuna.tsinghua.edu.cn/simple
# Configure Docker daemon for insecure registry
cat > /etc/docker/daemon.json <<EOF
{"registry-mirrors": ["https://owcyje1z.mirror.aliyuncs.com"], "insecure-registries": ["http://192.168.1.64:8181"]}
EOF
systemctl daemon-reload
systemctl restart docker

Running the Jenkins job triggers the full CI/CD flow: source checkout → Maven build → Docker image creation → image push to Harbor.

The next chapter will extend this process to full Kubernetes deployment.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

DockerPythonci/cdKubernetesDevOpsSpringBootJenkins
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.