Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
206 views
in Technique[技术] by (71.8m points)

kubernetes - Helm best practices

I am new to helm and liked the idea of helm to create versions for the deployments and package them as artifact in jfrog articatory but one thing that I am unclear about is easiness of creating it.

I am comfortable with kubernetes mainfest and creating it is very simple where you don't have to handcraft a yaml.

You can simply run kubectl command in dry-run mode and export most of the yaml tags as below:

kubectl run nginx --image=nginx --dry-run=client -o yaml > nginx-manifest.yaml

Now for creating helm, I need to run helm create and key in all the values needed by helm yaml files.

Curious if helm has such shortcuts that kubectl provides to create charts easily which keys in required value through command line while generating charts?

Also is there a migration utility available that supports converting the deployment manifest to helm charts?

question from:https://stackoverflow.com/questions/65944652/helm-best-practices

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

helm create does what you are looking for. It creates a directory with all the basic stuff so that you don't need to manually create each file/directory. However, it can't create the content of a Chart it has no clue about.

But, there is no magic behind the scenes, a chart consists in templates and values. The templates are the same YAML files you are used to work with, except that you can replace whatever you want to make "dynamic" with the placeholders used by Helm. That's it.

So, in other words, just keep exporting as you are (I strongly suggest stopping doing this and create proper files suited for your needs) and add placeholders ({{ .Values.foo }})

For example, this is the template for a service I have:

apiVersion: v1
kind: Service
metadata:
  name: {{ .Values.name | default .Chart.Name }}
spec:
  ports:
  - port: {{ .Values.port }}
    protocol: TCP
    targetPort: {{ .Values.port }}
  selector:
    app: {{ .Values.name | default .Chart.Name }}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...