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

[WEB][42108] Kubernetes deployment: Replicas number limitation #35

Open
JulienBertrand opened this issue Apr 6, 2023 · 0 comments
Open

Comments

@JulienBertrand
Copy link

\newpage

Sustainable Kubernetes deployment: Replicas number limitation

Platform

OS OS version Langage
- - Kubernetes (yaml)

Main caracteristics

ID Title Category Sub-category
CRKUB003 limit replicas number Deployment Sustainable deploy

Severity / Remediation Cost

Severity Remediation Cost
Minor Minor

Rule short description

In a Kubernetes deployment file, define a high replicas number is useless and consume unnecessary resources at startup.

Rule complete description

Text

In Kubernetes configuration, the desired replicas number at start can be defined in a yaml file.
Use a high number of replicas at start might not be a good idea because it will consumes unnecessary resources.
It is better to configure an horizontal pod autoscaling.

the value is define like this:

  • spec.replicas

HTML

<p>Defining the yaml file
    <code>---
      apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.7.9
        ports:
        - containerPort: 80</code> as example to perform a deployment.</p>
<p>Limit replicas number <code>replicas: x</code> to less than 3 and use horizontal pod autoscaling</p>
<h2>Noncompliant Code Example</h2>
<pre>
    <code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 8</code>
</pre>
<h2>Compliant Solution</h2>
<pre>
    <code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 2</code>
</pre>

Implementation principle

  • Inspect yaml file and find 'kind: Deployment'
  • Inspect the found file and find 'replicas: x'
  • Compare the replicas number to the limit
  • If the found value is above the limit, report the line
@JulienBertrand JulienBertrand changed the title [WEB][DRAFT][42108] Kubernetes deployment: Replicas number limitation [WEB][42108] Kubernetes deployment: Replicas number limitation Apr 6, 2023
@jhertout jhertout transferred this issue from green-code-initiative/creedengo-challenge May 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants