Kubernetes实战指南:零宕机无缝迁移Spring Cloud至k8s
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-spring-app
spec:
replicas: 3
selector:
matchLabels:
app: my-spring-app
template:
metadata:
labels:
app: my-spring-app
spec:
containers:
- name: my-spring-app
image: my-spring-app:latest
ports:
- containerPort: 8080
readinessProbe:
httpGet:
path: /actuator/health
port: 8080
initialDelaySeconds: 10
periodSeconds: 10
timeoutSeconds: 5
successThreshold: 1
failureThreshold: 5
livenessProbe:
httpGet:
path: /actuator/health
port: 8080
initialDelaySeconds: 10
periodSeconds: 10
timeoutSeconds: 5
successThreshold: 1
failureThreshold: 5
---
apiVersion: v1
kind: Service
metadata:
name: my-spring-app-service
spec:
selector:
app: my-spring-app
ports:
- protocol: TCP
port: 80
targetPort: 8080
type: LoadBalancer
这个代码实例展示了如何在Kubernetes上部署一个带有健康检查的Spring Boot应用。它定义了一个Deployment来创建应用的实例,并且定义了一个Service来暴露应用,使用LoadBalancer类型使得可以从外部访问应用。此外,健康检查被配置为HTTP GET请求,以确保Kubernetes知道应用实例是否健康。
评论已关闭