官术网_书友最值得收藏!

Scheduling example

Let's take a look at a quick example of setting some resource limits. If we look at our K8s dashboard, we can get a quick snapshot of the current state of resource usage on our cluster using https://<your master ip>/api/v1/proxy/namespaces/kube-system/services/kubernetes-dashboard and clicking on Nodes on the left-hand side menu.

We will see a dashboard as shown in the following screenshot:

Kube Node dashboard

This  view shows the aggregate CPU and memory across the whole cluster, nodes, and master. In this case, we have fairly low CPU utilization, but a decent chunk of memory in use.

Let's see what happens when I try to spin up a few more pods, but this time, we will request 512 Mi for memory and 1500 m for the CPU. We'll use 1500 m to specify 1.5 CPUs; since each node only has 1 CPU, this should result in failure. Here's an example of RC definition:

apiVersion: v1 
kind: ReplicationController
metadata:
name: node-js-constraints
labels:
name: node-js-constraints
spec:
replicas: 3
selector:
name: node-js-constraints
template:
metadata:
labels:
name: node-js-constraints
spec:
containers:
- name: node-js-constraints
image: jonbaier/node-express-info:latest
ports:
- containerPort: 80
resources:
limits:
memory: "512Mi"
cpu: "1500m"

Listing 2-12: nodejs-constraints-controller.yaml

To open the preceding file, use the following command:

$ kubectl create -f nodejs-constraints-controller.yaml

The replication controller completes successfully, but if we run a get pods command, we'll note the node-js-constraints pods are stuck in a pending state. If we look a little closer with the describe pods/<pod-id> command, we'll note a scheduling error (for pod-id use one of the pod names from the first command):

$ kubectl get pods
$ kubectl describe pods/<pod-id>

The following screenshot is the result of the preceding command:

Pod description

Note, in the bottom events section, that the WarningFailedScheduling pod error listed in Events is accompanied by fit failure on node....Insufficient cpu after the error. As you can see, Kubernetes could not find a fit in the cluster that met all the constraints we defined.

If we now modify our CPU constraint down to 500 m, and then recreate our replication controller, we should have all three pods running within a few moments.

主站蜘蛛池模板: 昔阳县| 湄潭县| 绍兴县| 涪陵区| 克东县| 安顺市| 偃师市| 神池县| 玛沁县| 蓬莱市| 应城市| 屏边| 密山市| 密山市| 安远县| 子长县| 南安市| 五家渠市| 读书| 巴青县| 余干县| 伽师县| 永修县| 中山市| 周至县| 新闻| 循化| 清徐县| 和林格尔县| 特克斯县| 新乐市| 翁牛特旗| 遂昌县| 安吉县| 嘉兴市| 盐山县| 宁明县| 鲁山县| 淅川县| 阳泉市| 河西区|