Difference Between Kubernetes yaml and Helm Chart
This is for my own understanding. Please don't assume it is 100% correct.
Difference: k8s configuration yaml vs helm Chart?
A helm chart is an abstraction that allows you to group multiple k8s configuration files into one package and deploy them together, as a template, and with variable substitution.
Helm is also a package manager like PHP's composer
or debian's apt
or node's npm
. That's an aside, as far as kubernetes config vs helm Chart, here's the breakdown:
Kubernetes configuration yaml and helm chart yaml looks similar at the top, with apiVersion
etc.
But, look closer, the Chart.yaml and the yaml files in the 'templates' directories are different. The Chart.yaml is formatted for helm to use while the template files are k8s manifest/configuration files that helm filters through it's template engine, replaces variables, and then outputs to kubectl apply
.
Helm also adds some labels and annotations indicating it is managing those configurations, and when you try to use helm later, like to upgrade a configuration, it will fail if those labels/annotations aren't set, so it doesn't start configuring something it hadn't originally installed.
This is that "helm is managing this" metadata:
{
"metadata": {
"labels": {
"app.kubernetes.io/managed-by": "Helm"
},
"annotations": {
"meta.helm.sh/release-name": "ingress-nginx",
"meta.helm.sh/release-namespace": "ingress-nginx"
}
}
}
This is how you can update it, if you had originally just done a kubectl apply -f
on some configuration data:
PATCH='
{
"metadata": {
"labels": {
"app.kubernetes.io/managed-by": "Helm"
},
"annotations": {
"meta.helm.sh/release-name": "ingress-nginx",
"meta.helm.sh/release-namespace": "ingress-nginx"
}
}
}
'
kubectl patch \
deployment ingress-nginx-controller \
--namespace ingress-nginx \
--type='merge' \
--patch "$PATCH"
After that, helm
will be aware of it (the labels and annotations will be stored in the cluster itself and helm will check for them before trying to apply any future changes), and will be able to act to upgrade, etc.
In the end, though, what helm appears to do is wrap the kubectl apply -f
command around the yaml file data in the templates/
directory. The Chart.yaml is about describing the chart and some versioning stuff, like a composer.json, package.json or docker-compose.yml. If you run helm template .
in a directory with a Chart.yaml file, it is somewhat like running composer
from a directory with composer.json or docker compose up
from a directory with a docker-compose.yml file.
In that case, running helm template .
will output all the files in the template directory combined into one big "yaml" file, concatenated together. If you want to replace variables in it, you would need to pass those in, like helm template . -f values.yaml
, or heml template . -f values1.yaml -f values2.yaml
. If you want to install, you would do helm upgrade --install . -f values.yaml
.