├── Dockerfile ├── README.md ├── app.yaml ├── deployment.yaml ├── pom.xml ├── service.yaml └── src ├── main ├── java │ └── com │ │ └── javatechie │ │ └── k8s │ │ └── SpringbootK8sDemoApplication.java └── resources │ └── application.properties └── test └── java └── com └── javatechie └── k8s └── SpringbootK8sDemoApplicationTests.java /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM openjdk:17 2 | EXPOSE 8080 3 | ADD target/springboot-k8s-demo.jar springboot-k8s-demo.jar 4 | ENTRYPOINT ["java","-jar","/springboot-k8s-demo.jar"] -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # springboot-k8s-example 2 | Deploy your spring boot application to kubernetes cluster 3 | -------------------------------------------------------------------------------- /app.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: argoproj.io/v1alpha1 2 | kind: Application 3 | metadata: 4 | name: myapp-argo-application 5 | namespace: argocd 6 | spec: 7 | project: default 8 | 9 | source: 10 | repoURL: https://github.com/Java-Techie-jt/springboot-k8s-example.git 11 | targetRevision: HEAD 12 | destination: 13 | server: https://kubernetes.default.svc 14 | namespace: spring-boot-k8s 15 | 16 | syncPolicy: 17 | syncOptions: 18 | - CreateNamespace=true 19 | 20 | automated: 21 | selfHeal: true 22 | prune: true -------------------------------------------------------------------------------- /deployment.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment # Kubernetes resource kind we are creating 3 | metadata: 4 | name: spring-boot-k8s 5 | spec: 6 | selector: 7 | matchLabels: 8 | app: spring-boot-k8s 9 | replicas: 2 # Number of replicas that will be created for this deployment 10 | template: 11 | metadata: 12 | labels: 13 | app: spring-boot-k8s 14 | spec: 15 | containers: 16 | - name: spring-boot-k8s 17 | image: springboot-k8s-example:1.0 18 | # Image that will be used to containers in the cluster 19 | imagePullPolicy: IfNotPresent 20 | ports: 21 | - containerPort: 8080 22 | # The port that the container is running on in the cluster -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 3.2.1 9 | 10 | 11 | com.javatechie 12 | springboot-k8s-demo 13 | 0.0.1-SNAPSHOT 14 | springboot-k8s-demo 15 | Demo project for Spring Boot 16 | 17 | 17 18 | 19 | 20 | 21 | org.springframework.boot 22 | spring-boot-starter-web 23 | 24 | 25 | 26 | org.springframework.boot 27 | spring-boot-starter-test 28 | test 29 | 30 | 31 | 32 | 33 | 34 | 35 | org.springframework.boot 36 | spring-boot-maven-plugin 37 | 38 | 39 | springboot-k8s-demo 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /service.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 # Kubernetes API version 2 | kind: Service # Kubernetes resource kind we are creating 3 | metadata: # Metadata of the resource kind we are creating 4 | name: springboot-k8s-svc 5 | spec: 6 | selector: 7 | app: spring-boot-k8s 8 | ports: 9 | - protocol: "TCP" 10 | port: 8080 # The port that the service is running on in the cluster 11 | targetPort: 8080 # The port exposed by the service 12 | type: NodePort # type of the service. -------------------------------------------------------------------------------- /src/main/java/com/javatechie/k8s/SpringbootK8sDemoApplication.java: -------------------------------------------------------------------------------- 1 | package com.javatechie.k8s; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.web.bind.annotation.GetMapping; 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | @SpringBootApplication 9 | @RestController 10 | public class SpringbootK8sDemoApplication { 11 | 12 | @GetMapping("/message") 13 | public String welcome(){ 14 | return "Congratulation you successfully deployed your application to kubernetes !!"; 15 | } 16 | 17 | public static void main(String[] args) { 18 | SpringApplication.run(SpringbootK8sDemoApplication.class, args); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /src/test/java/com/javatechie/k8s/SpringbootK8sDemoApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.javatechie.k8s; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class SpringbootK8sDemoApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | --------------------------------------------------------------------------------