Skip to content

Commit a39a164

Browse files
committed
address feedback
Signed-off-by: kirti763 <[email protected]>
1 parent 5387461 commit a39a164

File tree

1 file changed

+23
-21
lines changed
  • content/en/blog/_posts/2025-11-11-kubernetes-configuration-best-practices

1 file changed

+23
-21
lines changed

content/en/blog/_posts/2025-11-11-kubernetes-configuration-best-practices/index.md

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
---
22
layout: blog
3-
title: "Kubernetes Configuration Best Practices"
3+
title: "Kubernetes Configuration Good Practices"
44
date: 2025-11-11
5-
slug: kubernetes-configuration-best-practices
5+
slug: kubernetes-configuration-good-practices
66
evergreen: true
77
author: Kirti Goyal
88
draft: true
99
---
1010

11-
12-
## Introduction
13-
1411
Configuration is one of those things in Kubernetes that seems small until it's not. Configuration is at the heart of every Kubernetes workload.
15-
A missing quote, a wrong API version or a YAML indent can ruin your entire deploy.
12+
A missing quote, a wrong API version or a misplaced YAML indent can ruin your entire deploy.
1613

1714
This blog brings together tried-and-tested configuration best practices. The small habits that make your Kubernetes setup clean, consistent and easier to manage.
1815
Whether you are just starting out or already deploying apps daily, these are the little things that keep your cluster stable and your future self sane.
@@ -52,7 +49,9 @@ kubectl apply -f configs/
5249
One command and boom everything in that folder gets deployed.
5350

5451
### Add helpful annotations
55-
YAMl files are not just for machines, they are for humans too. Use annotations to describe why something exists or what it does. A quick one-liner can save hours when debugging later and also allows better collaboration.
52+
YAML files are not just for machines, they are for humans too. Use annotations to describe why something exists or what it does. A quick one-liner can save hours when debugging later and also allows better collaboration.
53+
54+
The most helpful annotation to set is `kubernetes.io/description`. It's like using comment, except that it gets copied into the API so that everyone else can see it even after you deploy.
5655

5756
## Managing Workloads: Pods, Deployments, and Jobs
5857

@@ -73,7 +72,7 @@ It will retry if the pods fails and report success when it's done.
7372

7473
## Service Configuration and Networking
7574

76-
Services are how your workloads talk to each other inside (and sometimes outside) your cluster. Without them, your pods exist but can't reach anyone. Let's make sure that doesn't happen
75+
Services are how your workloads talk to each other inside (and sometimes outside) your cluster. Without them, your pods exist but can't reach anyone. Let's make sure that doesn't happen.
7776

7877
### Create Services before workloads that use them
7978
When Kubernetes starts a Pod, it automatically injects environment variables for existing Services.
@@ -86,15 +85,15 @@ FOO_SERVICE_PORT=<the port the Service runs on>
8685
```
8786
DNS based discovery doesn't have this problem, but it's a good habit to follow anyway.
8887

89-
### Use DNS for service discovery
88+
### Use DNS for Service discovery
9089
If your cluster has the DNS [add-on](/docs/concepts/cluster-administration/addons/) (most do), every Service automatically gets a DNS entry. That means you can access it by name instead of IP:
9190
```bash
9291
curl http://my-service.default.svc.cluster.local
9392
```
9493
It's one of those features that makes Kubernetes networking feel magical.
9594

9695
### Avoid `hostPort` and `hostNetwork` unless absolutely necessary
97-
You'll see these options in YAMLs sometimes:
96+
You'll sometimes see these options in manifests:
9897
```yaml
9998
hostPort: 8080
10099
hostNetwork: true
@@ -108,7 +107,7 @@ If you just need local access for testing, try [`kubectl port-forward`](/docs/re
108107
```bash
109108
kubectl port-forward deployment/web 8080:80
110109
```
111-
See [Use Port Forwarding to Access Applications in a Cluster](/docs/tasks/access-application-cluster/port-forward-access-application-cluster/) to learn more.
110+
See [Use Port Forwarding to access applications in a cluster](/docs/tasks/access-application-cluster/port-forward-access-application-cluster/) to learn more.
112111
Or if you really need external access, use a [`type: NodePort` Service](/docs/concepts/services-networking/service/#type-nodeport). That's the safer, Kubernetes-native way.
113112

114113
### Use headless Services for internal discovery
@@ -118,7 +117,7 @@ You create one by setting `clusterIP: None`.
118117
Instead of a single IP, DNS gives you a list of all Pods IPs, perfect for apps that manage connections themselves.
119118

120119

121-
## Working with Labels Effectively
120+
## Working with labels effectively
122121

123122
[Labels](/docs/concepts/overview/working-with-objects/labels/) are key/value pairs that are attached to objects such as Pods.
124123
Labels help you organize, query and group your resources.
@@ -149,7 +148,7 @@ Basically you are not manually listing Pod names; you are just describing what y
149148
See the [guestbook](https://github.com/kubernetes/examples/tree/master/web/guestbook/) app for examples of this approach.
150149

151150
### Use common Kubernetes labels
152-
Kubernetes actually recommends a set of [common labels](/docs/concepts/overview/working-with-objects/common-labels/). It's a standarized way to name things across your different workloads or projects.
151+
Kubernetes actually recommends a set of [common labels](/docs/concepts/overview/working-with-objects/common-labels/). It's a standardized way to name things across your different workloads or projects.
153152
Following this convention makes your manifests cleaner, and it means that tools such as [Headlamp](https://headlamp.dev/), [dashboard](https://github.com/kubernetes/dashboard#introduction), or third-party monitoring systems can all
154153
automatically understand what's running.
155154

@@ -165,33 +164,34 @@ Once that happens, the controller won’t manage that Pod anymore.
165164
It’s like isolating it for inspection, a “quarantine mode” for debugging. To interactively remove or add labels, use [`kubectl label`](/docs/reference/kubectl/generated/kubectl_label/).
166165

167166
You can then check logs, exec into it and once done, delete it manually.
168-
169167
That’s a super underrated trick every Kubernetes engineer should know.
170168

171-
## Handy kubectl Tips for Managing Configs
169+
## Handy kubectl tips
172170

173171
These small tips make life much easier when you are working with multiple YAMLs or clusters.
174172

175173
### Apply entire directories
176174
Instead of applying one file at a time, apply the whole folder:
175+
177176
```bash
178-
kubectl apply -f configs/
177+
# Using server-side apply is also a good practice
178+
kubectl apply -f configs/ --server-side
179179
```
180180
This command looks for `.yaml`, `.yml` and `.json` files in that folder and applies them all together.
181181
It's faster, cleaner and helps keep things grouped by app.
182182

183183
### Use label selectors to get or delete resources
184184
You don't always need to type out resource names one by one.
185-
Instead, use [selectors]/docs/concepts/overview/working-with-objects/labels/#label-selectors) to act on entire groups at once:
185+
Instead, use [selectors](/docs/concepts/overview/working-with-objects/labels/#label-selectors) to act on entire groups at once:
186186

187187
```bash
188188
kubectl get pods -l app=myapp
189189
kubectl delete pod -l phase=test
190190
```
191191
It's especially useful in CI/CD pipelines, where you want to clean up test resources dynamically.
192192

193-
### Quickly create deployments and services
194-
For quick experiments, you don't always need to write YAMLs. You can spin up a deployment right from the CLI:
193+
### Quickly create Deployments and Services
194+
For quick experiments, you don't always need to write a manifest. You can spin up a Deployment right from the CLI:
195195

196196
```bash
197197
kubectl create deployment webapp --image=nginx
@@ -206,8 +206,10 @@ Also, see [Use a Service to Access an Application in a cluster](/docs/tasks/acce
206206

207207
## Conclusion
208208

209-
Clean configuration leads to calm clusters. If you stick to a few simple habits: version-control everything, use consistent labels, prefer YAML over JSON and avoid naked Pods you'll save yourself hours of debugging down the road.
209+
Cleaner configuration leads to calmer cluster administrators.
210+
If you stick to a few simple habits: keep configuration simple and minimal, version-control everything,
211+
use consistent labels, and avoid relying on naked Pods, you'll save yourself hours of debugging down the road.
210212

211213
The best part?
212-
Good configurations age well. Even months later, you (or others) will be able to read your manifests and understand exactly what's happening without confusion or chaos.
214+
Clean configurations stay readable. Even after months, you or anyone on your team can glance at them and know exactly whats happening.
213215

0 commit comments

Comments
 (0)