diff --git a/examples/cpu-manager/OWNERS b/examples/cpu-manager/OWNERS new file mode 100644 index 00000000000..152ded29de0 --- /dev/null +++ b/examples/cpu-manager/OWNERS @@ -0,0 +1,6 @@ +approvers: +- derekwaynecarr +- vishh +- ConnorDoyle +- sjenning +- balajismaniam diff --git a/examples/cpu-manager/README.md b/examples/cpu-manager/README.md new file mode 100644 index 00000000000..630d6c5b5c0 --- /dev/null +++ b/examples/cpu-manager/README.md @@ -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) diff --git a/examples/cpu-manager/be.yaml b/examples/cpu-manager/be.yaml new file mode 100644 index 00000000000..05d34a122b5 --- /dev/null +++ b/examples/cpu-manager/be.yaml @@ -0,0 +1,8 @@ +apiVersion: v1 +kind: Pod +metadata: + name: be +spec: + containers: + - image: quay.io/connordoyle/cpuset-visualizer + name: be diff --git a/examples/cpu-manager/exclusive-1.yaml b/examples/cpu-manager/exclusive-1.yaml new file mode 100644 index 00000000000..98dd57c810b --- /dev/null +++ b/examples/cpu-manager/exclusive-1.yaml @@ -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" diff --git a/examples/cpu-manager/exclusive-2.yaml b/examples/cpu-manager/exclusive-2.yaml new file mode 100644 index 00000000000..6003be0dd67 --- /dev/null +++ b/examples/cpu-manager/exclusive-2.yaml @@ -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" diff --git a/examples/cpu-manager/exclusive-3.yaml b/examples/cpu-manager/exclusive-3.yaml new file mode 100644 index 00000000000..25234fffe83 --- /dev/null +++ b/examples/cpu-manager/exclusive-3.yaml @@ -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" diff --git a/examples/cpu-manager/exclusive-4.yaml b/examples/cpu-manager/exclusive-4.yaml new file mode 100644 index 00000000000..da342acd2d9 --- /dev/null +++ b/examples/cpu-manager/exclusive-4.yaml @@ -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" diff --git a/examples/cpu-manager/pod-ips b/examples/cpu-manager/pod-ips new file mode 100755 index 00000000000..66ee355095d --- /dev/null +++ b/examples/cpu-manager/pod-ips @@ -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)"' diff --git a/examples/cpu-manager/shared.yaml b/examples/cpu-manager/shared.yaml new file mode 100644 index 00000000000..0f09d0c99f6 --- /dev/null +++ b/examples/cpu-manager/shared.yaml @@ -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