You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/en/blog/_posts/2025-11-11-kubernetes-configuration-best-practices/index.md
+23-21Lines changed: 23 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,18 +1,15 @@
1
1
---
2
2
layout: blog
3
-
title: "Kubernetes Configuration Best Practices"
3
+
title: "Kubernetes Configuration Good Practices"
4
4
date: 2025-11-11
5
-
slug: kubernetes-configuration-best-practices
5
+
slug: kubernetes-configuration-good-practices
6
6
evergreen: true
7
7
author: Kirti Goyal
8
8
draft: true
9
9
---
10
10
11
-
12
-
## Introduction
13
-
14
11
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.
16
13
17
14
This blog brings together tried-and-tested configuration best practices. The small habits that make your Kubernetes setup clean, consistent and easier to manage.
18
15
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/
52
49
One command and boom everything in that folder gets deployed.
53
50
54
51
### 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.
56
55
57
56
## Managing Workloads: Pods, Deployments, and Jobs
58
57
@@ -73,7 +72,7 @@ It will retry if the pods fails and report success when it's done.
73
72
74
73
## Service Configuration and Networking
75
74
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.
77
76
78
77
### Create Services before workloads that use them
79
78
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>
86
85
```
87
86
DNS based discovery doesn't have this problem, but it's a good habit to follow anyway.
88
87
89
-
### Use DNS for service discovery
88
+
### Use DNS for Service discovery
90
89
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:
91
90
```bash
92
91
curl http://my-service.default.svc.cluster.local
93
92
```
94
93
It's one of those features that makes Kubernetes networking feel magical.
95
94
96
95
### 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:
98
97
```yaml
99
98
hostPort: 8080
100
99
hostNetwork: true
@@ -108,7 +107,7 @@ If you just need local access for testing, try [`kubectl port-forward`](/docs/re
108
107
```bash
109
108
kubectl port-forward deployment/web 8080:80
110
109
```
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.
112
111
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.
113
112
114
113
### Use headless Services for internal discovery
@@ -118,7 +117,7 @@ You create one by setting `clusterIP: None`.
118
117
Instead of a single IP, DNS gives you a list of all Pods IPs, perfect for apps that manage connections themselves.
119
118
120
119
121
-
## Working with Labels Effectively
120
+
## Working with labels effectively
122
121
123
122
[Labels](/docs/concepts/overview/working-with-objects/labels/) are key/value pairs that are attached to objects such as Pods.
124
123
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
149
148
See the [guestbook](https://github.com/kubernetes/examples/tree/master/web/guestbook/) app for examples of this approach.
150
149
151
150
### 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.
153
152
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
154
153
automatically understand what's running.
155
154
@@ -165,33 +164,34 @@ Once that happens, the controller won’t manage that Pod anymore.
165
164
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/).
166
165
167
166
You can then check logs, exec into it and once done, delete it manually.
168
-
169
167
That’s a super underrated trick every Kubernetes engineer should know.
170
168
171
-
## Handy kubectl Tips for Managing Configs
169
+
## Handy kubectl tips
172
170
173
171
These small tips make life much easier when you are working with multiple YAMLs or clusters.
174
172
175
173
### Apply entire directories
176
174
Instead of applying one file at a time, apply the whole folder:
175
+
177
176
```bash
178
-
kubectl apply -f configs/
177
+
# Using server-side apply is also a good practice
178
+
kubectl apply -f configs/ --server-side
179
179
```
180
180
This command looks for `.yaml`, `.yml` and `.json` files in that folder and applies them all together.
181
181
It's faster, cleaner and helps keep things grouped by app.
182
182
183
183
### Use label selectors to get or delete resources
184
184
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:
186
186
187
187
```bash
188
188
kubectl get pods -l app=myapp
189
189
kubectl delete pod -l phase=test
190
190
```
191
191
It's especially useful in CI/CD pipelines, where you want to clean up test resources dynamically.
192
192
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:
195
195
196
196
```bash
197
197
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
206
206
207
207
## Conclusion
208
208
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.
210
212
211
213
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 what’s happening.
0 commit comments