文章目录
题目 1 HPA
设置配置环境 kubectl config use-context k8s
Task
在 autoscale namespace 中创建一个名为 apache-server 的新HorizontalPodAutoscaler(HPA)。
此 HPA 必须定位到 autoscale namespace 中名为apache-server 的现有 Deployment 。
将 HPA 设置为每个 Pod 的 CPU 使用率旨在 50% 。将其配置为至少有 1 个Pod,且不超过 4 个 Pod 。此外,将缩小稳定窗口设置为 30 秒。
官网答案:https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale-walkthrough/
apiVersion: apps/v1
kind: Deployment
metadata:
name: apache-server
namespace: autoscale
spec:
selector:
matchLabels:
run: apache-server
template:
metadata:
labels:
run: apache-server
spec:
containers:
- name: apache-server
image: registry.cn-shenzhen.aliyuncs.com/cookcodeblog/hpa-example
imagePullPolicy: IfNotPresent
ports:
- containerPort: 80
resources:
limits:
cpu: 500m
requests:
cpu: 200m
---
apiVersion: v1
kind