In the previous article, we introduced how to use NFS for file sharing and how to mount shared files in each Pod’s container.
Adjusting the Cluster Configuration
Update the cluster configuration:
1
| $ kubectl apply -f yml文件路径
|
Delete a deployment or service:
1
2
3
4
| # Delete Deployment
$ kubectl delete deployment 部署名称
# Delete Service
$ kubectl delete service 服务名称
|
Setting Cluster Resource Limits
We mainly add the resources configuration option to the container configuration to set resource limits.
1
2
3
4
5
6
7
8
9
10
| containers:
- name: tomcat-cluster
image: tomcat:latest
resources:
requests: # Minimum resource required to run the container, if not satisfied, cannot run
cpu: 1 # One nuclear cpu can be decimal, for example 0.5, which means that this container can be deployed as long as the host is 0.5 nuclear cpu is idle.
memory: 500Mi # 500M RAM
limits: # Most occupied resources during container operation
cpu: 2 # Up to 2 corecpu
memory: 1024Mi # Up to 1G RAM
|
Testing Resource Adjustments and Deployment
We modify the tomcat-deploy.yml file on the server, add resource limits, and increase the number of replicas to 3.
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
| apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: tomcat-deploy
spec:
replicas: 3 #Number of copies changed from 2 to 3
template:
metadata:
labels:
app: tomcat-cluster
spec:
volumes:
- name: web-app
hostPath:
path: /mnt
containers:
- name: tomcat-cluster
image: tomcat:latest
resources: # Additional resource limitations
requests:
cpu: 0.5
memory: 200Mi
limits:
cpu: 2
memory: 500Mi
ports:
- containerPort: 8080
volumeMounts:
- name: web-app
mountPath: /usr/local/tomcat/webapps
|
Update the cluster configuration:
1
| kubectl apply -f tomcat-deploy.yml
|
Check the cluster’s Pod information. The number of Pods has increased to 3.

It is worth noting that K8S follows a “resources first” principle when deploying Pods. In other words, a Pod is preferentially deployed to the node with more available resources.
Check whether the configuration has taken effect using the command kubectl describe pod tomcat-deploy-857545df88-26v5t.
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
| [root@master tomcat-deploy]# kubectl describe pod tomcat-deploy-857545df88-26v5t
Name: tomcat-deploy-857545df88-26v5t
Namespace: default
Priority: 0
PriorityClassName: <none>
Node: node2/192.168.233.130
Start Time: Fri, 15 Jan 2021 18:50:38 +0800
Labels: app=tomcat-cluster
pod-template-hash=857545df88
Annotations: <none>
Status: Running
IP: 10.244.2.11
Controlled By: ReplicaSet/tomcat-deploy-857545df88
Containers:
tomcat-cluster:
Container ID: docker://8f769d695c7f1713027a043a8e11edcf1ad3cb55ae731ca925c0573482174792
Image: tomcat:latest
Image ID: docker-pullable://tomcat@sha256:94cc18203335e400dbafcd0633f33c53663b1c1012a13bcad58cced9cd9d1305
Port: 8080/TCP
Host Port: 0/TCP
State: Running
Started: Fri, 15 Jan 2021 18:50:43 +0800
Ready: True
Restart Count: 0
Limits: # Resource constraints are in effect
cpu: 2
memory: 500Mi
Requests:
cpu: 500m
memory: 200Mi
Environment: <none>
Mounts:
/usr/local/tomcat/webapps from web-app (rw)
/var/run/secrets/kubernetes.io/serviceaccount from default-token-fkln2 (ro)
Conditions:
Type Status
Initialized True
Ready True
ContainersReady True
PodScheduled True
Volumes:
web-app:
Type: HostPath (bare host directory volume)
Path: /mnt
HostPathType:
default-token-fkln2:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-fkln2
Optional: false
QoS Class: Burstable
Node-Selectors: <none>
Tolerations: node.kubernetes.io/not-ready:NoExecute for 300s
node.kubernetes.io/unreachable:NoExecute for 300s
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 8m36s default-scheduler Successfully assigned default/tomcat-deploy-857545df88-26v5t to node2
Normal Pulling 8m35s kubelet, node2 Pulling image "tomcat:latest"
Normal Pulled 8m31s kubelet, node2 Successfully pulled image "tomcat:latest"
Normal Created 8m31s kubelet, node2 Created container tomcat-cluster
Normal Started 8m31s kubelet, node2 Started container tomcat-cluster
|