In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article is to share with you about how to use the chart template, the editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.
Helm uses templates to create resource configuration files in YAML format that Kubernetes can understand, and we will learn how to use templates through examples.
Take templates/secrets.yaml as an example:
In terms of structure, the content of the file is very similar to the Secret configuration, except that most of the property values become {{xxx}}. These {{xxx}} are actually the syntax of the template. Helm uses templates of the Go language to write chart. Go template is very powerful, supporting variables, objects, functions, flow control and other functions. Let's parse the templates/secrets.yaml Quick Learning template.
① {{template "mysql.fullname" > defines the name of the Secret.
The function of the keyword template is to reference a subtemplate mysql.fullname. This subtemplate is defined in the templates/_helpers.tpl file.
This definition is complex because it uses the concepts of objects, functions, flow control, and so on in the template language. It doesn't matter if you don't understand it now, the point we learn here is: if there is some information that multiple templates can use, you can define it as a subtemplate in templates/_helpers.tpl and then reference it through the templates function.
Here mysql.fullname consists of the concatenation of the names release and chart.
According to chart best practices, the names of all resources should be the same, and for our chart, whether Secret or Deployment, PersistentVolumeClaim, Service, their names are the values of the subtemplate mysql.fullname.
② Chart and Release are predefined objects for Helm, and each object has its own properties that can be used in templates. If you install chart using the following command:
Helm install stable/mysql-n my
So:
The value of {{.Chart.Name}} is mysql.
The value of {{.Chart.Version}} is 0.3.0.
The value of {{.Release.Name}} is my.
{{.Release.Service}} always takes the value Tiller.
{{template "mysql.fullname" > evaluates to my-mysql.
③ specifies the value of mysql-root-password here, but uses the flow control of if-else, whose logic is:
If .Values.mysqlRootPassword has a value, it is base64-encoded; otherwise, a 10-bit string is randomly generated and encoded.
Values is also a predefined object that represents an values.yaml file. The .Values.mysqlRootPassword is the mysqlRootPassword parameter defined in values.yaml:
Because mysqlRootPassword is commented out and there is no assignment, the logical judgment will go to else, that is, randomly generate passwords.
RandAlphaNum, b64enc and quote are all functions supported by the Go template language, and the functions can be connected through pipes. The function of {{randAlphaNum 10 | b64enc | quote}} is to first randomly generate a string of length 10, then encode it in base64, and finally put double quotation marks on both sides.
Templates/secrets.yaml this example shows the main functions of the chart template, our biggest gain should be: the template parameterized chart, through the values.yaml can be flexible to customize the application.
No matter how complex the application is, users can write chart in Go template language. Nothing more than the use of more functions, objects, and flow controls. For beginners, my advice is to refer to the official chart as much as possible. According to the law of 28, these chart already cover most cases and adopt best practices.
The above is how to use the chart template, the editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.