Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add example pods to demonstrate CPU manager. #51929

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions examples/cpu-manager/OWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
approvers:
- derekwaynecarr
- vishh
- ConnorDoyle
- sjenning
- balajismaniam
62 changes: 62 additions & 0 deletions examples/cpu-manager/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# CPU Manager Example

This example flow uses a pre-built docker image based on
[cpuset-visualizer](https://github.com/ConnorDoyle/cpuset-visualizer).
Each container run here hosts an endpoint serving an up-to-the-second
system representation generated by
[`lstopo`](https://www.open-mpi.org/projects/hwloc).

## Setup

1. Start a local cluster with the static CPU manager policy enabled :

```
sudo PATH=$PATH \
KUBELET_FLAGS="\
--feature-gates=CPUManager=true \
--cpu-manager-policy=static \
--cpu-manager-reconcile-period=5s \
--kube-reserved=cpu=500m" \
./hack/local-up-cluster.sh
```

## Run pods

The example pods are in the `/examples/cpu-manager` directory of the
Kubernetes source tree. Your ability to run all of the example pods
simultaneously depends on how many CPUs are available on the test system.

The required CPUs for each example pod are listed below:

```
POD | CPUs
------------------|---------
be.yaml | >= 1 CPU
shared.yaml | >= 1 CPU
exclusive-1.yaml | >= 2 CPU
exclusive-2.yaml | >= 3 CPU
exclusive-3.yaml | >= 4 CPU
exclusive-4.yaml | >= 5 CPU
```

### Example

Run a pod with a single container in the shared pool, and another pod
with a single container in an exclusive cpuset with one CPU.

```
$ kubectl create -f examples/cpu-manager/shared.yaml
$ kubectl create -f examples/cpu-manager/exclusive-1.yaml
```

To list IP addresses of the pods running in the local cluster, do:

```
$ watch ./examples/cpu-manager/pod-ips
exclusive-1 http://172.17.0.4
shared http://172.17.0.3
```

#### Sample cpuset-visualizer output

![Sample cpuset-visualizer output](https://user-images.githubusercontent.com/379372/28648573-974693ce-7223-11e7-84ed-17cce11910ff.png)
8 changes: 8 additions & 0 deletions examples/cpu-manager/be.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: v1
kind: Pod
metadata:
name: be
spec:
containers:
- image: quay.io/connordoyle/cpuset-visualizer
name: be
15 changes: 15 additions & 0 deletions examples/cpu-manager/exclusive-1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v1
kind: Pod
metadata:
name: exclusive-1
spec:
containers:
- image: quay.io/connordoyle/cpuset-visualizer
name: exclusive-1
resources:
requests:
cpu: 1
memory: "256M"
limits:
cpu: 1
memory: "256M"
15 changes: 15 additions & 0 deletions examples/cpu-manager/exclusive-2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v1
kind: Pod
metadata:
name: exclusive-2
spec:
containers:
- image: quay.io/connordoyle/cpuset-visualizer
name: exclusive-2
resources:
requests:
cpu: 2
memory: "256M"
limits:
cpu: 2
memory: "256M"
15 changes: 15 additions & 0 deletions examples/cpu-manager/exclusive-3.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v1
kind: Pod
metadata:
name: exclusive-3
spec:
containers:
- image: quay.io/connordoyle/cpuset-visualizer
name: exclusive-3
resources:
requests:
cpu: 3
memory: "256M"
limits:
cpu: 3
memory: "256M"
15 changes: 15 additions & 0 deletions examples/cpu-manager/exclusive-4.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v1
kind: Pod
metadata:
name: exclusive-4
spec:
containers:
- image: quay.io/connordoyle/cpuset-visualizer
name: exclusive-4
resources:
requests:
cpu: 4
memory: "256M"
limits:
cpu: 4
memory: "256M"
26 changes: 26 additions & 0 deletions examples/cpu-manager/pod-ips
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

# Copyright 2017 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Requires `jq`. See https://stedolan.github.io/jq/download

set -o nounset -o pipefail -o errexit

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
KUBECTL="$DIR/../../cluster/kubectl.sh"
export KUBECONFIG="${KUBECONFIG:-/var/run/kubernetes/admin.kubeconfig}"

$KUBECTL get pods -o json | \
jq -r '.items[] | "\(.metadata.name) http://\(.status.podIP)"'
11 changes: 11 additions & 0 deletions examples/cpu-manager/shared.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v1
kind: Pod
metadata:
name: shared
spec:
containers:
- image: quay.io/connordoyle/cpuset-visualizer
name: shared
resources:
requests:
cpu: 100m