Hey everyone! I'm just getting started with Kubernetes and currently working with a file named `demo.yaml` that includes all my services, deployments, ingress, and a kustomization.yaml file. My kustomization file looks like this:
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- https://github.com/cert-manager/cert-manager/releases/download/v1.18.2/cert-manager.yaml
- demo.yml
This setup worked well for learning about different workloads until I encountered a syntax error in my `demo.yaml`. I ran `kubectl apply -k .`, and it executed without any error message, making it difficult to debug why my cluster wasn't behaving like I expected.
As I anticipate working with multiple YAML files in the future, I'm curious about how others write their manifest files to avoid these types of issues. Do you use a linter, a different language like CUE, or some other methods?
5 Answers
A good tip is to run your `kubectl apply` command with the dry run option: `kubectl apply -f some-manifest.yaml --dry-run=server`. This checks your file for errors before actually applying it. Also, using the Kubernetes VSC extension can help since it has plenty of snippets available. I typically copy a working resource and modify it as needed.
I usually just copy and paste from previous deployments or find reliable helm charts on GitHub or Artifact Hub. It's a quick way to get started without diving into the details each time.
When using kustomize, I recommend doing `kustomize build . | kubectl diff -f -`. This way, you can see the full manifest output and compare what's about to change before you apply it.
Using suitable VSC plugins is crucial. And remember, nothing goes to production unless it's gone through a CI pipeline that validates it in a pre-production environment first.
Just a heads up, invoking `kubectl apply -k /path/to/manifest` is not the same as `kustomize build /path/to/manifest`. They might behave differently depending on their versions. Always check compatibility between your kubectl version and the Kubernetes server version. I also use Python's yamllint for linting my YAML files; it really helps catch errors before going live.
Related Questions
How To Get Your Domain Unblocked From Facebook
How To Find A String In a Directory of Files Using Linux