Step-by-Step Jenkins Pipeline for Deploying Spring Cloud Microservices with Docker and Kubernetes
This tutorial explains how to automate the full lifecycle of a Spring Cloud microservice—from developers pushing code to Git, Jenkins pulling and building it with Maven, packaging the JAR into a Docker image, pushing the image to a private registry, and finally deploying or updating the service on a Kubernetes cluster using YAML manifests.
The article describes a one‑click deployment workflow for Spring Cloud microservices that leverages Jenkins, Docker, and Kubernetes. The process begins with developers pushing code to a Git repository, after which Jenkins automatically pulls the code, builds it with Maven, and creates a Docker image that is pushed to a private Docker registry.
Key steps include configuring SSH keys for password‑less git clone, adding the public key to the Git platform (e.g., Gitee), and testing the SSH connection. Jenkins jobs are created as pipeline projects with a parameter for the Git branch version.
Pipeline scripts are provided to pull the code, compile it across multiple modules, and package the final JAR. A build.sh script builds the Docker image, tags it with the branch, commit hash, and timestamp, and pushes it to the registry. The Dockerfile copies the JAR and configuration files and defines the entry point.
After the image is built, a Kubernetes deployment and service YAML file are prepared. Placeholders like IMAGE_AND_TAG are replaced with the actual image name and tag, and the manifest is applied with kubectl apply -f to create or update the service, exposing port 20881 and mounting a log directory.
The article also shows how to start a local Docker registry, make the build.sh script executable, and verify the deployment by checking the registry for the new image and querying Kubernetes resources with kubectl get all. Screenshots illustrate each Jenkins configuration step and the final successful deployment.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Selected Java Interview Questions
A professional Java tech channel sharing common knowledge to help developers fill gaps. Follow us!
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
