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

Modify rule S6873: Add examples for LimitRange #4015

Merged
merged 1 commit into from
Jun 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 42 additions & 2 deletions rules/S6873/kubernetes/rule.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ might crash, causing downtime for all containers running on that node.

=== Code examples

To avoid potential issues specify a memory request for each container with `resources.requests.memory`.
To avoid potential issues, either specify a memory request for each container in a pod specification
or create a resource of a kind, `LimitRange`,
that sets a default memory request for all containers in all pod specifications belonging to the same namespace.

==== Noncompliant code example

Expand All @@ -53,6 +55,19 @@ spec:
image: nginx
----

[source,yaml,diff-id=2,diff-type=noncompliant]
----
apiVersion: v1
kind: Pod
metadata:
name: example
spec:
containers:
- name: web # Noncompliant
image: nginx
----


==== Compliant solution

[source,yaml,diff-id=1,diff-type=compliant]
Expand All @@ -70,11 +85,36 @@ spec:
memory: 100Mi
----

[source,yaml,diff-id=2,diff-type=compliant]
----
apiVersion: v1
kind: LimitRange
metadata:
name: mem-limit-range
namespace: default-mem-example
spec:
limits:
- type: Container
defaultRequest:
memory: 100Mi
---
apiVersion: v1
kind: Pod
metadata:
name: example
namespace: default-mem-example
spec:
containers:
- name: web
image: nginx
----


=== How does this work?

A request can be set through the property `resources.requests.memory` of a
container. Alternatively, a default request for a namespace can be set with
`LimitRange`.
`LimitRange` through `spec.limits[].defaultRequest.memory`.

== Resources

Expand Down
Loading