Skip to content

Commit

Permalink
Merge pull request #1140 from network-charles/network-charles-patch-2
Browse files Browse the repository at this point in the history
Scheduler Testing with KWOK (Technical Outcome)
  • Loading branch information
k8s-ci-robot committed Jul 17, 2024
2 parents ad14bb7 + a422971 commit bfd571c
Show file tree
Hide file tree
Showing 39 changed files with 4,924 additions and 1 deletion.
32 changes: 32 additions & 0 deletions site/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ menu:
- identifier: contributing
pageRef: "/docs/contributing"
weight: 30
# Technical Outcomes
- identifier: technical-outcomes
title: Technical Outcomes
- identifier: technical-outcomes-scheduling
pageRef: "/docs/technical-outcomes/scheduling"
parent: technical-outcomes

# User Guide Children
- identifier: all-in-one-image
Expand Down Expand Up @@ -267,6 +273,32 @@ menu:
pageRef: "/docs/contributing/development"
parent: contributing

# Technical Outcome Scheduling Children
- identifier: technical-outcomes-scheduling-requests-and-limits
title: "Requests and Limits"
pageRef: "/docs/technical-outcomes/scheduling/requests-and-limits"
parent: technical-outcomes-scheduling
- identifier: technical-outcomes-scheduling-node-affinity
title: "Node Affinity"
pageRef: "/docs/technical-outcomes/scheduling/node-affinity"
parent: technical-outcomes-scheduling
- identifier: technical-outcomes-scheduling-taints-and-tolerations
title: "Taints and Tolerations"
pageRef: "/docs/technical-outcomes/scheduling/taints-and-tolerations"
parent: technical-outcomes-scheduling
- identifier: technical-outcomes-scheduling-limit-range
title: "Limit Range"
pageRef: "/docs/technical-outcomes/scheduling/limit-range"
parent: technical-outcomes-scheduling
- identifier: technical-outcomes-scheduling-pod-priority-and-preemption
title: "Pod Priority and Preemption"
pageRef: "/docs/technical-outcomes/scheduling/pod-priority-and-preemption"
parent: technical-outcomes-scheduling
- identifier: technical-outcomes-scheduling-pod-topology-spread-constraint
title: "Pod Topology Spread Constraint"
pageRef: "/docs/technical-outcomes/scheduling/pod-topology-spread-constraint"
parent: technical-outcomes-scheduling

after:
- identifier: blog
pageRef: "/posts"
Expand Down
4 changes: 3 additions & 1 deletion site/content/en/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ which means that simulating a large number of nodes and pods requires a lot of m

### What's the difference with `kind`

[kind] runs Kubernetes in Docker, creating a real cluster.
[kind] runs Kubernetes in Docker, creating a real cluster. If you deploy a nginx pod to a
[kind] cluster, you could curl to its IP address and get an HTTP response containing its HTML
page. But in a KWOK cluster, you get nothing because the pod isn't real.

`kwokctl` can be used as an alternative to [kind] in some scenarios where you don’t need to actually run any pod.

Expand Down
24 changes: 24 additions & 0 deletions site/content/en/docs/technical-outcomes/scheduling/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
title: Scheduler Testing
---

# Scheduler Testing with KWOK

{{< hint "info" >}}

This document walks you through the technical outcome of using KWOK for scheduler tests.

{{< /hint >}}

KWOK can be used to create fake nodes and pods in a simulated cluster.
The cluster can be configured with scheduling policies that meet your scheduler's requirements.
The scenarios below can be used to describe this:

- [Scheduling pods with resource requests and limits](/docs/technical-outcomes/scheduling/requests-and-limits)
- [Scheduling a pod to a particular node with node-affinity](/docs/technical-outcomes/scheduling/node-affinity)
- [Scheduling pods with taints and tolerations](/docs/technical-outcomes/scheduling/taints-and-tolerations)
- [Scheduling pods with a limit range](/docs/technical-outcomes/scheduling/limit-range)
- [Scheduling pods using pod priority and preemption](/docs/technical-outcomes/scheduling/pod-priority-and-preemption)
- [Scheduling pods using pod topology spread constraints](/docs/technical-outcomes/scheduling/pod-topology-spread-constraint)

Other scheduling scenarios can also be simulated using KWOK.
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
---
title: "Limit Range"
---

# Scheduling pods with a limit range

A limit range schedule policy can be used in a KWOK cluster.

<img width="700px" src="limit-range.svg">

## Prerequisites

- KWOK must be installed on the machine. See [installation](https://kwok.sigs.k8s.io/docs/user/installation/).
- Install [kubectl](https://kubernetes.io/docs/tasks/tools/install-kubectl-linux/)

## Create cluster

```bash
kwokctl create cluster
```

## View clusters

This ensures that the cluster was created successfully.

```bash
kwokctl get clusters
```

## Create nodes

```bash
kwokctl scale node --replicas 1
```

## Create a resource limit

{{< expand "limit-range.yaml" >}}

{{< code-sample file="limit-range.yaml" >}}

{{< /expand >}}

```bash
kubectl apply -f limit-range.yaml
```

## Confirm the limit has the required values

```bash
kubectl describe limitranges cpu-resource-constraint

Name: cpu-resource-constraint
Namespace: default
Type Resource Min Max Default Request Default Limit Max Limit/Request Ratio
---- -------- --- --- --------------- ------------- -----------------------
Container cpu 100m 1 500m 500m -
```

## Deploy a pod above the resource limit

- Pod specification:
- CPU Request: 700m

{{< expand "pod-beyond-limit.yaml" >}}

{{< code-sample file="pod-beyond-limit.yaml" >}}

{{< /expand >}}

```bash
kubectl create -f pod-beyond-limit.yaml
```

Notice the error `Invalid value: "700m": must be less than or equal to cpu limit of 500m`

## Deploy a pod within the resource limit

- Pod specification:
- CPU Request: 400m

{{< expand "pod-within-limit.yaml" >}}

{{< code-sample file="pod-within-limit.yaml" >}}

{{< /expand >}}

```bash
kubectl apply -f pod-within-limit.yaml
```

## Confirm that the pod is running

```bash
kubectl get pod

NAME READY STATUS RESTARTS AGE
pod-within-limit 1/1 Running 0 10s
```

## Delete the cluster

```bash
kwokctl delete cluster
```

## Conclusion

This example demonstrates how to use KWOK to simulate a scheduling
scenario based on setting a [limit range](https://kubernetes.io/docs/concepts/policy/limit-range/) policy.
Loading

0 comments on commit bfd571c

Please sign in to comment.