Skaffold is a command-line tool that facilitates continuous development for Kubernetes-native applications. It automates the build, push, and deploy process, allowing developers to focus on writing code. For this project, Skaffold is configured to work with a Spring Boot application using Jib for building Docker images.
- apiVersion: Specifies the version of the Skaffold configuration.
- kind: Defines the type of configuration, which is
Configin this case. - metadata: Contains metadata about the project, such as the name.
- build: Defines how the application should be built. This project uses Jib to build the Docker image.
- artifacts: Lists the artifacts to be built. Here, it specifies the image name and the Jib project.
- manifests: Lists the Kubernetes manifests to be deployed, including deployment and service YAML files.
apiVersion: skaffold/v4beta12
kind: Config
metadata:
name: spring-boot-skaffold
build:
artifacts:
- image: springboot-skaffold
jib:
project: id.my.hendisantika:skaffold
manifests:
rawYaml:
- k8s/deployment.yml
- k8s/service.yml- Build: Skaffold uses Jib to build the Docker image for the Spring Boot application.
- Push: The built image is pushed to a container registry.
- Deploy: The Kubernetes manifests are applied to the cluster, deploying the application.
This setup streamlines the development process, enabling rapid iteration and deployment of changes to the Kubernetes cluster.
-
Install Skaffold:
- Follow the installation instructions from the Skaffold documentation.
-
Configure
skaffold.yaml:- Ensure your
skaffold.yamlfile is correctly configured as shown in the provided example.
- Ensure your
-
Build and Deploy:
- Open a terminal in the root directory of your project.
- Run the following command to build and deploy your application using Skaffold:
skaffold dev
-
Access Your Application:
- Once deployed, you can access your Spring Boot application using the service URL provided by your Kubernetes cluster.
-
Port Forward our app
skaffold dev --port-forward
-
Or via k8s cmd:
minikube service list
or
minikube service spring-boot-app
http://localhost:8080/api/v1/hendi
// 20250312095725
// http://localhost:8080/api/v1/hendi
[
{
"userId": 1,
"lastName": "YUJI",
"firstName": "ITADORI",
"position": "father"
},
{
"userId": 2,
"lastName": "KUGISAKI",
"firstName": "NAOBARA",
"position": "mother"
},
{
"userId": 3,
"lastName": "RYOUMEN",
"firstName": "SUKUNA",
"position": "son"
},
{
"userId": 4,
"lastName": "SUGURU",
"firstName": "GETO",
"position": "uncle"
},
{
"userId": 5,
"lastName": "MEGUMI",
"firstName": "FUSHIGURO",
"position": "grandfather"
}
]These steps will help you set up and use Skaffold for continuous development with your Spring Boot project.