题目要求

在现有的 namespace pod-resources中创建一个名为nginx-resources 的 Pod 。镜像为 nginx:1.16 ,为其容器指定资源请求40m的 CPU 和50Mi的内存

参考

https://kubernetes.io/zh-cn/docs/concepts/configuration/manage-resources-containers/

官方示例:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
---
apiVersion: v1
kind: Pod
metadata:
name: frontend
spec:
containers:
- name: app
image: images.my-company.example/app:v4
resources:
requests:
memory: "64Mi"
cpu: "250m"
limits:
memory: "128Mi"
cpu: "500m"

解答

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# 1.1 创建pod配置
kubectl run nginx-resources --image=nginx:1.16 --dry-run=client -o yaml > 4.pod-resources.yaml
cat 4.pod-resources.yaml

apiVersion: v1
kind: Pod
metadata:
creationTimestamp: null
labels:
run: nginx-resources
name: nginx-resources
spec:
containers:
- image: nginx:1.16
name: nginx-resources
resources: {}
dnsPolicy: ClusterFirst
restartPolicy: Always
status: {}

# 1.2 根据题目要求修改request
apiVersion: v1
kind: Pod
metadata:
creationTimestamp: null
labels:
run: nginx-resources
name: nginx-resources
spec:
containers:
- image: nginx:1.16
name: nginx-resources
resources:
requests:
memory: "50Mi"
cpu: "40m"
dnsPolicy: ClusterFirst
restartPolicy: Always
status: {}
# 1.3 部署
kubectl apply -f 4.pod-resources.yaml