Kubernetes Configuration Good Practices
Kubernetes Configuration Good Practices Configuration is one of those things in Kubernetes that seems small until it's not. Configuration is at the heart of every Kubernetes workload. A missing quote, a wrong API version or a misplaced YAML indent can ruin your entire deploy. This blog brings together tried-and-tested configuration best practices. The small habits that make your Kubernetes setup clean, consistent and easier to manage. 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. This blog is inspired by the original Configuration Best Practices page, which has evolved through contributions from many members of the Kubernetes community. General configuration practices Use the latest stable API version Kubernetes evolves fast. Older APIs eventually get deprecated and stop working. So, whenever you are defining resources, make sure you are using the latest stable API version. You can always check with kubectl api-resources This simple step saves you from future compatibility issues. Store configuration in version control Never apply manifest files directly from your desktop. Always keep them in a version control system like Git, it's your safety net. If something breaks, you can instantly roll back to a previous commit, compare changes or recreate your cluster setup without panic. Write configs in YAML not JSON Write your configuration files using YAML rather than JSON. Both work technically, but YAML is just easier for humans. It's cleaner to read and less noisy and widely used in the community. YAML has some sneaky gotchas with boolean values: Use only true or false . Don't write yes , no , on or off . They might work in one version of YAML but break in another. To be safe, quote anything that looks like a Boolean (for example "yes" ). Keep configuration simple and minimal Avoid setting default values that are already handled by Kubernetes. Minimal manifests are easier to debug, cleaner to review and less likely to break things later. Group related objects together If your Deployment, Service and ConfigMap all belong to one app, put them in a single manifest file. It's easier to track changes and apply them as a unit. See the Guestbook all-in-one.yaml file for an example of this syntax. You can even apply entire directories with: kubectl apply -f configs/ One command and boom everything in that folder gets deployed. Add helpful annotations Manifest 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. 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. Managing Workloads: Pods, Deployments, and Jobs A common early mistake in Kubernetes is creating Pods directly. Pods work, but they don't reschedule themselves if something goes wrong. Naked Pods...
Preview: ~500 words
Continue reading at Kubernetes
Read Full Article