使用Kubernetes,Spring Boot和Flyway實現零停機部署原始碼專案
這是個Github示例專案,展示如何使用Kubernetes,Kotlin+Spring Boot和Flyway實現零停機時間部署.
主程式:
@SpringBootApplication class ZeroDowntimeApplication { @Bean fun displayInfo(context: Context) = CommandLineRunner { println("START: ${context.hostname} (running v${context.version})") } @Bean fun context() = Context() } fun main(args: Array<String>) { runApplication<ZeroDowntimeApplication>(*args) } @Controller class PersonController(private val repository: PersonRepository, private val context: Context) { @GetMapping("/") fun getAll(model: Model): String { println("GET : ${context.hostname} (running v${context.version})") model["person"] = Person() model["persons"] = repository.findAll() model["title"] = "Person ${context.hostname} (v${context.version})" return "/persons" } @PostMapping("/") fun create(@Valid person: Person, result: BindingResult): String { println("POST: ${context.hostname} (running v${context.version})") repository.save(person) return "redirect:/" } } interface PersonRepository : JpaRepository<Person, Long> |
模型類:
@Entity class Person(@Id @GeneratedValue(strategy = IDENTITY) var id: Long = -1, val name: String = "") { @OneToOne(mappedBy = "person", cascade = [CascadeType.ALL]) @JoinColumn(name = "id") val address: Address = Address() init { address.person = this } } @Entity class Address(@Id @GeneratedValue(strategy = IDENTITY) var id: Long? = null, var addressLine1: String = "", var addressLine2: String? = null, var city: String = "", var zipCode: String = "") { @OneToOne @JoinColumn(name = "person_id") lateinit var person: Person } |
application.yml:
spring: jpa: hibernate.ddl-auto: validate open-in-view: false datasource: url: jdbc:h2:tcp://localhost:1521/~/zerodowntime username: sa driver-class-name: org.h2.Driver info: app: version: @project.version@ |
Kubernetes部署application.yml:
apiVersion: v1 kind: Namespace metadata: name: zerodowntime --- apiVersion: v1 kind: Service metadata: namespace: zerodowntime name: app-service spec: selector: role: app ports: - port: 8080 nodePort: 30002 type: NodePort --- apiVersion: apps/v1 kind: Deployment metadata: name: application namespace: zerodowntime spec: replicas: 3 minReadySeconds: 10 selector: matchLabels: role: app strategy: rollingUpdate: maxSurge: 0 maxUnavailable: 1 type: RollingUpdate template: metadata: labels: role: app spec: containers: - name: spring-boot-app image: zerodowntime:1.0 imagePullPolicy: Never readinessProbe: periodSeconds: 2 httpGet: path: /actuator/health port: 8080 env: - name: spring.datasource.url value: jdbc:h2:tcp://db-service:1521/~/zerodowntime ports: - containerPort: 8080 |
點選標題見原始碼
相關文章
- Kubernetes中部署Spring Boot專案(七)Spring Boot
- 使用 Docker 部署 Spring Boot 專案DockerSpring Boot
- 使用Docker部署Spring Boot專案DockerSpring Boot
- 使用 Docker 部署 Spring Boot 專案,帶勁!!DockerSpring Boot
- Spring Boot 整合 Flyway 實現資料庫版本控制Spring Boot資料庫
- Spring Boot + Junit 5 + Testcontainers原始碼專案Spring BootAI原始碼
- 使用Spring Boot, Istio和Cert Manager實現Kubernetes的HTTPSSpring BootHTTP
- 在Docker中部署Spring Boot專案DockerSpring Boot
- 使用SDM快速部署Spring Boot應用到KubernetesSpring Boot
- 使用Docker實現Spring Boot Restful Web服務案例原始碼DockerSpring BootRESTWeb原始碼
- Maven 搭建spring boot多模組專案(附原始碼)MavenSpring Boot原始碼
- 使用Kubernetes和Istio實現藍綠部署
- 使用 Hibernate 和 H2 的多租戶Spring Boot開源原始碼專案Spring Boot原始碼
- Spring Boot專案部署到外部TomcatSpring BootTomcat
- 使用Spring Boot實現微服務架構的開源專案Spring Boot微服務架構
- 使用Spring Boot和Kafka Streams實現CQRSSpring BootKafka
- Spring Boot + JPA實現MySQL批量更新原始碼 - githubSpring BootMySql原始碼Github
- Spring Boot中實現規則引擎原始碼教程Spring Boot原始碼
- Linux雲服務部署Spring boot專案LinuxSpring Boot
- 使用Spring Boot實現檔案上傳功能Spring Boot
- Spring Boot 2 實戰:使用 Flyway 管理你資料庫的版本變更Spring Boot資料庫
- 使用 Docker 部署 Spring BootDockerSpring Boot
- Spring Boot 2.0(四):使用 Docker 部署 Spring BootSpring BootDocker
- Spring Boot(十六):使用 Jenkins 部署 Spring BootSpring BootJenkins
- Spring Boot Flyway管理資料庫版本 - josdemSpring Boot資料庫
- spring-boot專案的docker整合化部署(一)SpringbootDocker
- Spring Boot專案微信雲託管入門部署Spring Boot
- 使用gradle搭建spring boot專案GradleSpring Boot
- 使用Spring Boot開發Web專案Spring BootWeb
- 在spring boot專案(maven)中引入其他 spring boot專案Spring BootMaven
- 使用 Spring Boot 3.2 和 CRaC 實現更快啟動Spring Boot
- spring boot碼雲原始碼Spring Boot原始碼
- 使用Spring Boot實現模組化Spring Boot
- Spring Boot系列(四):Spring Boot原始碼解析Spring Boot原始碼
- 使用Spring Boot排程WebSocket推送的教程和原始碼 - BaeldungSpring BootWeb原始碼
- 在Kubernetes上使用Spring Boot實現Hazelcast分散式快取 – PiotrSpring BootAST分散式快取
- 基於Jenkins自動化部署spring boot專案JenkinsSpring Boot
- 搭建 Jenkins-2.83 服務,部署 spring boot 專案JenkinsSpring Boot