kubernetes - Kubernetes 备用/冷副本/Pod
问题描述
我正在寻找如何在我的 Kubernetes 配置中拥有备用/冷副本/pod。我假设它会出现在我的 Kuberentes 部署或 HPA 配置中。知道我将如何做到这一点,因此我的应用程序的 2 个备用/冷实例始终准备就绪,但只有在 HPA 请求另一个实例时才被放入活动 pod?我的目标是当 HPA 说它需要另一个实例时,新 pod 的启动时间基本上为零。
apiVersion: apps/v1
kind: Deployment
metadata:
name: someName
namespace: someNamespace
labels:
app: someName
version: "someVersion"
spec:
replicas: $REPLICAS
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: someMaxSurge
maxUnavailable: someMaxUnavailable
selector:
matchLabels:
app: someName
version: someVersion
template:
metadata:
labels:
app: someName
version: "someVersion"
spec:
containers:
- name: someName
image: someImage:someVersion
imagePullPolicy: Always
resources:
limits:
memory: someMemory
cpu: someCPU
requests:
memory: someMemory
cpu: someCPU
readinessProbe:
failureThreshold: someFailureThreshold
initialDelaySeconds: someInitialDelaySeconds
periodSeconds: somePeriodSeconds
timeoutSeconds: someTimeoutSeconds
livenessProbe:
httpGet:
path: somePath
port: somePort
failureThreshold: someFailureThreshold
initialDelaySeconds: someInitialDelay
periodSeconds: somePeriodSeconds
timeoutSeconds: someTimeoutSeocnds
---
apiVersion: policy/v1beta1
kind: PodDisruptionBudget
metadata:
name: someName
namespace: someNamespace
spec:
minAvailable: someMinAvailable
selector:
matchLabels:
app: someName
version: "someVersion"
---
apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
name: someName-hpa
namespace: someNamespace
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: someName
minReplicas: someMinReplicas
maxReplicas: someMaxReplicas
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: someAverageUtilization
解决方案
我只是想总是有 2 个备用用于扩展,或者如果一个变得不可用或任何原因
在 Kubernetes 上至少有两个服务副本是一个很好的做法。如果某个节点出现故障或您需要维护该节点,这会有所帮助。还要设置Pod 拓扑传播约束,以便这些 pod 被安排在不同的节点上运行。
将所需的最低副本数设置为所需的状态。在 Kubernetes 中,流量将负载均衡到副本。还可以使用Horizontal Pod Autoscaler来定义何时要自动缩放到更多副本。如果您想尽早扩展,可以将自动扩展的要求设置得较低。
推荐阅读
- python - Python 用列表在字典中舍入 UP/DOWN 整数
- database - 如何在 Laravel 中具有两个 with() 值的雄辩查询中使用 orderBy?
- html - 在图像上的垂直组中对齐文本中心
- javascript - 如何在 react js 中实现表单验证?
- sql - 更改 BigQuery 中的列更正错字
- reactjs - useReducer() 仅返回初始状态
- python - 需要解决与某些特定模型相关联的用户 Django 身份验证和创建用户的方法
- routes - 在一个请求中,参数 Laravel 的路由参数从何而来?
- android - 给定 url 不允许应用程序配置 ionic facebook login android
- java - 在 Spring Boot Actuator 的 /metrics 端点中未显示远程 tomcat 的 tomcat.session.* 指标