13 Kubernetes Configurations You Should Know in 2k24


 

As Kubernetes continues to be the cornerstone of container orchestration, mastering its mechanisms and capabilities is becoming imperative for DevOps professionals. In 2024, some Kubernetes configurations stand out due to their automation and security features, as well as performance improvements in cloud-native environments. This article discusses 13 key Kubernetes configurations and offers an immersive dive into each of them with use cases, benefits, and code examples.

1. Resource Requests and Limits

Understanding and correctly configuring requests and limits on resource usage are fundamental in Kubernetes. Requests and limits ensure that your applications get the resources they need to run, while at the same time preventing any single application from utilizing all the resources in the cluster.

apiVersion: v1
kind: Pod
metadata:
name: sample-app
spec:
containers:
- name: app-container
image: nginx
resources:
requests:
memory: "64Mi"
cpu: "250m"
limits:
memory: "128Mi"
cpu: "500m"
  • Why you need it: Increase the stability and performance of both individual applications and the cluster as a whole. Prevent resource contention and ensure that applications are not unexpectedly terminated due to resource constraints

  • Who benefits: Kubernetes administrators and developers who want to optimize application performance and cluster resource utilization

  • When to apply: Setting up requests and limits is required for all applications running in the cluster (workload). The right configuration ensures predictable performance and prevents a single application from consuming a disproportionate amount of resources, impacting the stability of the entire cluster

  • Documentation: Resource Management for Pods and Containers

2. Checking liveliness and readiness

Configuring liveness probes and readiness probes is critical to managing the lifecycle of your applications on Kubernetes. They help Kubernetes make decisions about when to restart the container (determine liveness) and when the container is ready to start processing traffic (determine readiness).

livenessProbe:
httpGet:
path: /healthz
port: 8080
initialDelaySeconds: 3
periodSeconds: 3
readinessProbe:
httpGet:
path: /ready
port: 8080
initialDelaySeconds: 5
periodSeconds: 5
  • Why you should: Improve the resiliency and availability of your applications by ensuring that Kubernetes can automatically manage the state of containers based on the actual health of the application, not just the state of the container runtime

  • Who benefits: Developers and operators who publish mission-critical services that require high availability and self-healing

  • When to apply: Setting up liveness checking is required for applications that require maximum availability and minimal downtime. Configuration of readiness check is required for applications that should receive traffic only after they are fully initialized and confirm that they are ready to process requests

  • Documentation: Configure Liveness, Readiness and Startup Probes

3. Configuration dictionaries and secrets

Config Maps and Secrets are required to infer configuration parameters and sensitive data from application code. Configuration dictionaries allow you to store open data in the key-value format, and secrets - confidential information.

apiVersion: v1
kind: ConfigMap
metadata:
name: app-config
data:
config.json: |
{
"database": "sql",
"timeout": "30s",
"featureFlag": "true"
}
---
apiVersion: v1
kind: Secret
metadata:
name: app-secret
type: Opaque
data:
password: cGFzc3dvcmQ=
  • Why you need it: Detach configuration settings and secrets from application logic, simplify application deployment and management across environments, and improve security

  • Who can benefit from it: Any Kubernetes user who manages applications that require configuration data or need to securely handle credentials and other sensitive information

  • When to use: Configuration dictionaries are used to specify application parameters that change depending on the environment (dev, staging, production). Secrets are used for credentials, tokens, and other sensitive information

  • Documentation: ConfigMaps, Secrets

4. Horizontal autoscaling

Horizontal Pod Autoscaler (HPA) automatically adjusts the number of pod replicas in a Deployment, ReplicaSet, or StatefulSet based on processor utilization or user metrics.

apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
metadata:
name: sample-app-hpa
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: sample-app
minReplicas: 1
maxReplicas: 10
targetCPUUtilizationPercentage: 80
  • Why you need it: Guaranteed scale-out based on current load, optimal resource utilization, and performance

  • Who can benefit from: Administrators and DevOps professionals who want to automate application scaling based on real-time needs

  • When to apply: Setting up horizontal autoscaling is ideal for applications with variable traffic. It provides dynamic resource allocation to meet demand without manual intervention

  • Documentation: Horizontal Pod Autoscaling

5. Network Policies

Network Policies are Kubernetes resources that manage the flow of traffic between pods and network endpoints, enabling micro-segmentation and improving the security of your Kubernetes applications.

apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: default-deny-all
spec:
podSelector: {}
policyTypes:
- Ingress
- Egress
  • Why you need it: Secure communication between pods within a Kubernetes cluster – only authorized traffic will be transferred between modules or to external services

  • Who benefits: Kubernetes administrators and security engineers who need to enforce strict network security policies on their clusters

  • When to apply: Configuring network policies is especially useful in multi-tenant environments or applications with high security requirements to prevent unauthorized access and limit potential attack vectors

  • Documentation: Network Policies

6. Service Accounts

Service Accounts in Kubernetes are used to identify pods when interacting with the Kubernetes API and other services within the cluster. They are critical for access control and ensuring secure inter-service communication.

apiVersion: v1
kind: ServiceAccount
metadata:
name: my-service-account
namespace: default
  • Using an account in the pod:

apiVersion: v1
kind: Pod
metadata:
name: my-pod
spec:
containers:
- name: my-container
image: my-image
serviceAccountName: my-service-account
  • Why you need it: Assigning pods to an account allows for granular access control and auditing of work. Accounts are also required to provide access to the Kubernetes API and other cluster resources

  • Who can benefit from: Kubernetes cluster administrators and developers who need to securely manage access to the API server and Kubernetes resources from pods

  • When to apply: Accounts are used to deploy applications that need to interact with the Kubernetes API or authenticate to other services within the cluster. These can be automation jobs or microservices that require specific permissions

  • Documentation: Configure Service Accounts for Pods

7. Ingress Resources and Ingress Controllers

Ingress resources and Ingress controllers control external access to services in the cluster, usually using the HTTP protocol. They allow you to define rules for routing traffic to different services.

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: example-ingress
spec:
rules:
- host: www.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: example-service
port:
number: 80
  • Why you need it: Providing a centralized, scalable, and secure method for managing access to your Kubernetes services from the internet.)

  • Who benefits: DevOps professionals and Kubernetes administrators who manage public-facing applications

  • When to use: Ingress controllers and Ingress resources are a must for any application that requires controlled access from outside the Kubernetes cluster. Especially useful when managing multiple services or performing URL-based routing

  • Documentation: Ingress, Ingress Controllers

8. Permanent Volumes

Persistent Volumes (PVs) and Persistent Volume Claims (PVC) are handy storage management tools in Kubernetes that abstract the details of data storage and handling.

apiVersion: v1
kind: PersistentVolume
metadata:
name: example-pv
spec:
capacity:
storage: 10Gi
accessModes:
- ReadWriteOnce
nfs:
path: /path/to/data
server: nfs-server.example.com
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: example-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
  • Why you need it: Persistent data retention for stateful applications outside of the pod lifecycle

  • Who benefits from it: engineers who work with databases, file storage, and other stateful applications in Kubernetes

  • When to use: PV and PVC are used when an application requires persistent data retention independent of the pod lifecycle. This ensures data durability and availability

  • Documentation: Persistent Volumes

9. Role-based access control

Role-Based Access Control (RBAC) allows you to apply granular access control policies to Kubernetes resources using roles and role binding to restrict permissions within the cluster.

apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
namespace: default
name: pod-reader
rules:
- apiGroups: [""]
resources: ["pods"]
verbs: ["get", "watch", "list"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: read-pods
namespace: default
subjects:
- kind: User
name: "jane"
apiGroup: rbac.authorization.k8s.io
roleRef:
kind: Role
name: pod-reader
apiGroup: rbac.authorization.k8s.io
  • Why you need it: Least privilege across the entire Kubernetes cluster. This principle ensures that users and applications have only the permissions they need

  • Who benefits from it: cluster administrators and engineers who take care of information security and implement secure access policies

  • When to apply: RBAC is used when you need to provide secure access to Kubernetes resources, especially in multi-user or multi-team environments

  • Documentation: Using RBAC Authorization

10. Custom Resource Definitions

Custom Resource Definitions (CRDs) allow you to extend the Kubernetes API with self-written additional resources and thus add the new functionality that you need.

apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: crontabs.stable.example.com
spec:
group: stable.example.com
names:
kind: CronTab
listKind: CronTabList
plural: crontabs
singular: crontab
scope: Namespaced
versions:
- name: v1
served: true
storage: true
schema:
openAPIV3Schema:
type: object
properties:
spec:
type: object
properties:
cronSpec:
type: string
image:
type: string
  • Why you need it: Create and manage your own objects, easily integrate with Kubernetes APIs and kubectl tools

  • Who can benefit from it: Developers and operators who want to embed custom operations or resources into their Kubernetes environment

  • When to use: CRDs allow you to extend the capabilities of Kubernetes when existing resources do not meet the specific needs of the application

  • Documentation: Extend the Kubernetes API with CustomResourceDefinitions

11. Limitations and Tolerances

Taints and Tolerations work together to ensure that pods are not run on unsuitable cluster nodes.

apiVersion: v1
kind: Node
metadata:
name: node1
spec:
taints:
- key: "key1"
value: "value1"
effect: NoSchedule
  • Why you need it: Managing the placement of pods on nodes, taking into account the features of hardware, software, and other user requirements

  • Who can benefit from: Cluster administrators who want to optimize workload balancing and ensure separation of user environments

  • When to apply: Constraints and tolerances are used to prevent certain tasks from running on certain nodes and thus allocating those nodes to a specific workload

  • Documentation: Taints and Tolerations

12. Similarity and anti-similarity

Affinity and anti-affinity settings allow you to control where pods should (or shouldn't) be placed relative to other pods.

apiVersion: apps/v1
kind: Deployment
metadata:
name: with-pod-affinity
spec:
selector:
matchLabels:
app: with-pod-affinity
template:
metadata:
labels:
app: with-pod-affinity
spec:
affinity:
podAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: security
operator: In
values:
- S1
topologyKey: "kubernetes.io/hostname"
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 100
podAffinityTerm:
labelSelector:
matchExpressions:
- key: security
operator: In
values:
- S2
topologyKey: "kubernetes.io/hostname"
  • Why you need to: Manage the distribution of pods across the cluster to improve fault tolerance, availability, or meet other operational requirements

  • Who benefits: Administrators and developers who want to customize pod allocation to optimize performance or comply with regulatory requirements

  • When to apply: Affinity and anti-affinity settings ensure high availability and distribute the workload according to security or other conditions

  • Documentation: Assigning Pods to Nodes

13. Completing tasks according to the schedule

Jobs manage tasks that should be run once, and Cron jobs (CronJobs) manage tasks that need to be run on a schedule.

apiVersion: batch/v1
kind: Job
metadata:
name: example-job
spec:
template:
spec:
containers:
- name: hello
image: busybox
command: ["sh", "-c", "echo Hello Kubernetes! && sleep 30"]
restartPolicy: Never
---
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: example-cronjob
spec:
schedule: "*/5 * * * *"
jobTemplate:
spec:
template:
spec:
containers:
- name: hello
image: busybox
command: ["sh", "-c", "echo Hello Kubernetes! && sleep 30"]
restartPolicy: OnFailure
  • Why you need it: Automate tasks in Kubernetes such as backup, maintenance, or batch execution

  • Who benefits: Engineers who automate routine tasks or execute batches of jobs in Kubernetes environments

  • When to use: Jobs and Cron jobs allow you to run jobs once or on a schedule

  • Documentation: Jobs, CronJob

Resume

These Kubernetes configurations are the foundation for building reliable, efficient, and secure cloud applications. Understanding and applying these settings will allow you to take full advantage of the power of Kubernetes, tailor deployments to your specific needs, and adhere to optimal operational standards. 


We Got More Tools For #Price

https://t.me/redfishiaven

#Update #tutorial #rianews #software #hardware #technology #money #earning #ipmc #love #giveaways #computing #computers #informationtechnology #learning #AI #redfishiaven #servers #deepweb #darkweb #bitcoin #cybersecurity

See REDFISH IA VEN ( https://goo.gl/maps/LVKkEYNN2LTe9C34A ) in Google Maps.

https://www.youtube.com/channel/UC6k_cFigPCSEtRyALo1D-tA

Be the First To Know About The New #software

Comments

Popular posts from this blog

Short Codes for Mobile Networks in Ghana (2025)

How to Enable Audio over Remote Desktop?

Gold Or Bitcoin