Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Install EMQ X on Kubernetes part 3: using Helm to manage and deploy EMQ X clusters

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

Helm introduction

Helm is a tool for managing Kubernetes packages, and Helm provides the following capabilities:

Create a new charts package charts as a tgz file to interact with the chart repository to install and uninstall Kubernetes applications to manage the lifecycle of charts installed using Helm

There are three important concepts to understand in Helm:

Chart: a collection of information to create an instance of an Kubernetes application; config: a running instance of the configuration information release:chart of the chart that creates the publishing object, including specific configHelm components

There are two main components in Helm, the Helm client and the Tiller server:

Helm client: this is a command line tool for end users, and the client is responsible for the following:

The local chart development management repository interacts with the Tiller server to send charts requests that need to be installed for information about the release version, request to update or uninstall the installed release version

Tiller server: the Tiller service is deployed in the Kubernetes cluster, and the Helm client interacts with the Tiller server and eventually with the Kubernetes API server. The Tiller server is responsible for the following tasks:

Listen for requests from Helm clients to combine chart and configuration to build a release installed in Kubernetes and track subsequent releases by interacting with Kubernetes, updates, or chart

The client is responsible for managing the chart and the server development is responsible for managing the release.

Helm technology implementation

The Helm client is written in the Go language and interacts with the Tiller server through the gRPC protocol.

The Tiller server is also written in the Go language and uses the Kubernetes client class library (currently that REST+JSON) to communicate with Kubernetes.

The Tiller server stores information through Kubernetes's ConfigMap, so it is not used to store the database itself.

Helm installation deployment install Helm client

Before you install the Helm client, verify that a Kubernetes cluster environment is available and that kubectl is installed.

By visiting: https://github.com/kubernetes/helm/releases.

Download the appropriate version of Helm.

Download the helm-v2.8.0-linux-amd64.tgz version; extract the file: tar-zxvf helm-v2.8.0-linux-amd64.tgz move the extracted helm to the / usr/local/bin directory: mv linux-amd64/helm / usr/local/bin/helm

Note:

It is best to install the Helm client on the machine where the kubectl command line tool is installed, or copy the configuration file generated by installing the kubectl command line tool ($HOME/.kube/config) to the machine installed by the Helm client ($HOME/.kube/config). Install the Tiller server using Service Account installation

Create a Service Account named tiller

$kubectl create serviceaccount tiller-namespace kube-system

Grant the Service Account cluster administrator role named tiller cluster-admin:

The yaml file that binds tiller to the cluster administrator role is as follows:

$vim rbac-config.yamlapiVersion: rbac.authorization.k8s.io/v1beta1 kind: ClusterRoleBinding metadata: name: tiller roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: cluster-admin subjects:-kind: ServiceAccount name: tiller namespace: kube-system

The tiller cluster administrator role will be granted by executing kubectl create-f:

$kubectl create-f rbac-config.yaml

Install the Tiller server

$helm init-- service-account tiller verifies the installation

After the installation is complete, you can check whether the installation is successful by executing the following command:

$helm version

If the versions of the Helm client and Tiller server are displayed correctly, this indicates that the installation was successful.

Or check to see if you have followed the Tiller server properly by executing the following command from kubectl:

$kubectl get pods-n kube-systemHelm uses common commands to view the source helm repo list # to list all sources. Currently, no source has been added # add an Ali source that can be accessed domestically, but it seems that helm repo add ali https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts has not been updated recently. If you can connect to the public network, you can add google. F8helm repo add google https://kubernetes-charts.storage.googleapis.com helm repo add fabric8 https://fabric8.io/helm# update source helm repo update View chart# View chart, that is, applications that have been deployed to the K8s platform via helm helm list or helm ls# to view or search the Helm charts in the repository Type any of the following command helm search helm search repository name # such as stable or incubatorhelm search chart name # such as wordpress or spark# to view charm details helm inspect ali/wordpress download charthelm fetch ali/wordpress [ubuntu@master1 ~] # ls wordpress-0.8.8.tgz wordpress-0.8.8.tgz deployment application wordpress Through the ali source file $helm install-- name wordpress-test-- set "persistence.enabled=false Mariadb.persistence.enabled=false "ali/wordpress [ubuntu@master1 ~] # kubectl get pod NAME READY STATUS RESTARTS AGEwordpress-test-mariadb-84b866bf95-7bx5w 1 Running 1 4hwordpress-test-wordpress-5ff8c64b6c-hrh9q 1 kubectl get svc NAME TYPE 1 Running 0 4h [ubuntu@master1 ~] # kubectl get svc NAME TYPE CLUSTER-IP EXTERNAL-IP PORT (S) AGEkubernetes ClusterIP 10.96.0.1 443/TCP 2dwordpress-test-mariadb ClusterIP 10.105.71.95 3306/TCP 4hwordpress-test-wordpress LoadBalancer 10.104.106.150 80:30655/TCP 443:32121/TCP 4h visits wordpress Use node node ip + nodeport, 192.168.1.181 helm listNAME REVISION UPDATED STATUS CHART NAMESPACEwordpress-test 30655 delete application [ubuntu@master1 ~] # helm listNAME REVISION UPDATED STATUS CHART NAMESPACEwordpress-test 1 Thu May 17 11:35:07 2018 DEPLOYED wordpress-0.8.8 default [ubuntu@master1 ~] # helm delete wordpress-testrelease "wordpress-test" deleted to establish your own chart

Create your own chart, look at the document structure, and learn how to use the

$helm create emqxCreating emqx$ tree misa86emqx ├── charts # Chart itself version and configuration information ├── Chart.yaml # Chart itself version and configuration information ├── templates # configuration template directory │ ├── deployment.yaml # kubernetes Deployment object │ ├── _ helpers.tpl # template for modifying kubernetes objcet configuration │ ├── ingress.yaml # kubernetes Deployment object │ ├── NOTES .txt # helm prompt │ └── service.yaml # kubernetes Serivce └── values.yaml # kubernetes object configuration Define variable template template

Template contains all the yaml file templates for applications. The types of application resources are not limited to deployment and service, but can be supported by K8s.

$cat templates/deployment.yamlapiVersion: apps/v1beta2kind: Deploymentmetadata: name: {{include "emqx.fullname". }} labels: app.kubernetes.io/name: {{include "emqx.name". }} helm.sh/chart: {{include "emqx.chart". }} app.kubernetes.io/instance: {{.Release.Name}} app.kubernetes.io/managed-by: {{.Release.Service}} spec: replicas: {{.Values.replicaCount} selector: matchLabels: app.kubernetes.io/name: {{include "emqx.name". }} app.kubernetes.io/instance: {{.Release.Name}} template: metadata: labels: app.kubernetes.io/name: {{include "emqx.name". } app.kubernetes.io/instance: {{.Release.Name}} spec: containers:-name: {{.Chart.Name}} image: "{{.Values.image.repository}: {{.Values.image.tag}}" imagePullPolicy: {{.Values.image.pull Policy}} ports:-containerPort: 1883 -containerPort: 8883-containerPort: 8080-containerPort: 8083-containerPort: 8084-containerPort: 18083 env:-name: EMQX_NAME value: emqx-name: EMQX_CLUSTER__K8S__APP_NAME value: emqx-name: EMQX_CLUSTER__DISCOVERY value: K8s -name: EMQX_CLUSTER__K8S__SERVICE_NAME value: {{include "emqx.fullname". }-name: EMQX_CLUSTER__K8S__APISERVER value: {{.Values.env.kubeApiserver}}-name: EMQX_CLUSTER__K8S__NAMESPACE value: {{.Values.env.kubeNamespace}}-name: EMQX_CLUSTER__K8S__ADDRESS_TYPE value: {{.Values.env.kubeAddressType}}-name: EMQX_CLUSTER__K8S__APP_NAME value: emqx tty: true

This is the yaml configuration file of the Deploymen t of the application, in which the double curly braces package expands the part is Go template, template "emqx.name" is defined in the _ helpers.tpl file, if not defined, the future file name will be an arbitrary character plus chart name.

The Values is defined in the values.yaml file, and the main parameters for application are here:

$cat values.yaml# Default values for emqx.# This is a YAML-formatted file.# Declare variables to be passed into your templates.replicaCount: 2image: repository: emqx/emqx tag: latest pullPolicy: IfNotPresentenv: kubeApiserver: http://127.0.0.1:8080 kubeNamespace: default kubeAddressType: ipservice: type: ClusterIP mqttPort: 1883 mqttsslPort: 8883 mgmtPort: 8080 webscoketPort:8083 wssPort:8084 dashboardPort: 18083ingress: enabled: false annotations: {} # kubernetes.io/ingress.class: nginx # kubernetes.io / tls-acme: "true" path: / hosts:-chart-example.local tls: [] #-secretName: chart-example-tls # hosts: #-chart-example.local

For example, the container image image defined in Deployment.yaml:

{{.Values.image.repository}}: {{.Values.image.tag}}

Among them:

.Values.image.repository is emqx/emqx.Values.image.tag and latest

The above two variable values are the default values that are automatically generated during install chart.

Check whether the configuration and template are valid

When using kubernetes to deploy the application, the templates is actually rendered into a yaml format that the final kubernetes can recognize.

Use the helm install-- dry-run-- debug command to verify the chart configuration. The output contains the variable configuration of the template and the final rendered yaml file. The first half of the name of deployment service consists of two random words, a random number plus a chart name. The name can also be changed to value, and you can define that if there are problems with the configuration, an error will be reported here.

Helm install-- set env.kubeApiserver= http://172.31.31.241:8080-- dry-run-- debug. [debug] Created tunnel using local port: '43251' [debug] SERVER: "127.0.0.1 debug 43251" [debug] Original chart version: "" [debug] CHART PATH: / / home/ubuntu/emqx-helmNAME: quelling-toadREVISION: 1RELEASED: Tue Oct 30 08:18:09 2018CHART: emqx-helm-v1.0USER-SUPPLIED VALUES:env: kubeApiserver: http: / / 172.31.31.241:8080COMPUTED VALUES:env: kubeAddressType: ip kubeApiserver: http://172.31.31.241:8080 kubeNamespace: defaultimage: pullPolicy: IfNotPresent tag: latestingress: annotations: {} enabled: false hosts:-chart-example.local path: / tls: [] replicaCount: 2service: dashboardPort: 18083 mappingPort: 4369 mgmtPort: 8080 mqttPort: 1883 mqttsslPort: 8883 type: ClusterIPHOOKS:MANIFEST:---# Source: emqx-helm/templates/service.yamlapiVersion: v1kind: Servicemetadata : name: quelling-toad-emqx-helm labels: app.kubernetes.io/name: emqx-helm helm.sh/chart: emqx-helm-v1.0 app.kubernetes.io/instance: quelling-toad app.kubernetes.io/managed-by: Tillerspec: type: ClusterIP ports:-name: mqtt port: 1883 protocol: TCP targetPort: 1883-name: mqttssl port: 8883 protocol: TCP targetPort: 8883-name: mgmt port: 8080 protocol: TCP targetPort : 8080-name: webscoket port: 8083 protocol: TCP targetPort: 8083-name: wss port: 8084 protocol: TCP targetPort: 8084-name: dashboard port: 18083 protocol: TCP targetPort: 18083 selector: app.kubernetes.io/name: emqx-helm app.kubernetes.io/instance: quelling-toad---# Source: emqx-helm/templates/deployment.yamlapiVersion: apps/v1beta2kind: Deploymentmetadata: name: quelling-toad-emqx-helm labels: app.kubernetes. Io/name: emqx-helm helm.sh/chart: emqx-helm-v1.0 app.kubernetes.io/instance: quelling-toad app.kubernetes.io/managed-by: Tillerspec: replicas: 2 selector: matchLabels: app.kubernetes.io/name: emqx-helm app.kubernetes.io/instance: quelling-toad template: metadata: labels: app.kubernetes.io/name: emqx-helm app.kubernetes.io/instance: Quelling-toad spec: containers:-name: emqx-helm image: "emqx/emqx:latest" imagePullPolicy: IfNotPresent ports:-containerPort: 1883-containerPort: 8883-containerPort: 8080-containerPort: 8083-containerPort: 8084-containerPort: 18083 env:-name: EMQX_NAME Value: emqx- name: EMQX_CLUSTER__K8S__APP_NAME value: emqx- name: EMQX_CLUSTER__DISCOVERY value: K8s-name: EMQX_CLUSTER__K8S__SERVICE_NAME value: quelling-toad-emqx-helm-name: EMQX_CLUSTER__K8S__APISERVER value: http://172. 31.31.241 default 8080-name: EMQX_CLUSTER__K8S__NAMESPACE value: default-name: EMQX_CLUSTER__K8S__ADDRESS_TYPE value: ip-name: EMQX_CLUSTER__K8S__APP_NAME value: emqx tty: true deploy to kubernetes

Execute the following command from the EMQ X directory to deploy the application to the kubernetes cluster.

$helm install-- set env.kubeApiserver= http://172.31.31.241:8080 .name: ugly-bumblebeeLAST DEPLOYED: Tue Oct 30 08:19:17 2018NAMESPACE: defaultSTATUS: DEPLOYEDRESOURCES:== > v1/ServiceNAME AGEugly-bumblebee-emqx-helm 0slots = > v1beta2/Deploymentugly-bumblebee-emqx-helm 0slots = > v1/Pod (related) NAME READY STATUS RESTARTS AGEugly-bumblebee-emqx-helm-5bc599849f -n4htc 0 0sugly-bumblebee-emqx-helm-5bc599849f-xwdn7 1 ContainerCreating 0 0sNOTES:1 0 0sNOTES:1. Get the application URL by running these commands: export POD_NAME=$ (kubectl get pods-- namespace default-l "app.kubernetes.io/name=emqx-helm App.kubernetes.io/instance=ugly-bumblebee "- o jsonpath=" {.items [0] .metadata.name} ") echo" Visit http://127.0.0.1:8080 to use your application "kubectl port-forward $POD_NAME 8080 jsonpath= 80 View deployed relaese$ helm listNAME REVISION UPDATED STATUS CHART APP VERSION NAMESPACEugly-bumblebee 1 Tue Oct 30 08:19:17 2018 DEPLOYED emqx -helm-v1.0 v1.0 default$ helm delete ugly-bumblebeerelease "ugly-bumblebee" deleted package sharing

We can modify the helm chart configuration information in Chart.yaml and then package chart into a compressed file using the following command.

$helm package .successful packaged chart and saved it to: / home/ubuntu/emqx/emqx-v1.0.tgzChart Repository

The chart library is a HTTP server with an index.yaml file and any packaged chart. When you are ready to share chart, the preferred way is to upload it to the chart library.

Because the chart library can be any HTTP server that can provide YAML and tar files and answer GET requests, there are many options when hosting your own chart library. For example, you can use Google Cloud Storage (GCS) buckets, Amazon S3 buckets, Github Pages, or even create your own Web server.

Create chart library chart library structure

The chart library consists of a packaged chart and a special file named index.yaml that contains the index of all the chart in the chart library. Typically, the chart described by index.yaml is also hosted on the same server, as do source code files.

For example, the layout https://example.com/charts of the chart library might look like this:

Charts/ | |-index.yaml | |-alpine-0.1.2.tgz | |-alpine-0.1.2.tgz.prov

In this case, the index file contains information about a chart (Alpine chart) and provides a download URL https://example.com/charts/alpine-0.1.2.tgz for that chart.

It is not required that the chart package reside on the same server as the index.yaml file. However, it is usually the easiest to put it together.

Index file

The index file is a yaml file called index.yaml. It contains some metadata about the package, including the contents of chart's Chart.yaml file. A valid chart library must have an index file. The index file contains information about each chart in the chart library. The helm repo index command generates an index file based on the given local directory that contains the packaged chart.

The following is an example of an index file:

ApiVersion: v1entries: alpine:-created: 2016-10-06T16:23:20.499814565-06:00 description: Deploy a basic Alpine Linux pod digest: 99c76e403d752c84ead610644d4b1c2f2b453a74b921f422b9dcb8a7c8b559cd home: https://k8s.io/helm name: alpine sources:-https://github.com/kubernetes/helm urls:-https://technosophos.github.io/tscharts/alpine-0.2.0.tgz version: 0.2.0- Created: 2016-10-06T16:23:20.499543808-06:00 description: Deploy a basic Alpine Linux pod digest: 515c58e5f79d8b2913a10cb400ebb6fa9c77fe813287afbacf1a0b897cd78727 home: https://k8s.io/helm name: alpine sources:-https://github.com/kubernetes/helm urls:-https://technosophos.github.io/tscharts/alpine-0.1.0.tgz version: 0.1.0 nginx:-created: 2016-10-06T16: 2320.499543808-06:00 description: Create a basic nginx HTTP server digest: aaff4545f79d8b2913a10cb400ebb6fa9c77fe813287afbacf1a0b897cdffffff home: https://k8s.io/helm name: nginx sources:-https://github.com/kubernetes/charts urls:-https://technosophos.github.io/tscharts/nginx-1.1.0.tgz version: 1.1.0generated: 2016-10-06T16:23:20.499029981-06:00

The generated indexes and packages can be provided from a basic network server. You can use helm serve to start the local server and test everything locally.

Helm serve-- repo-path. / chartsRegenerating index. This may take a moment.Now serving you on 127.0.0.1 8879 hosted chart library

To configure a normal Web server to serve Helm chart, simply do the following:

Place the index and chart in the server directory to ensure that index.yaml can access the yaml file without authentication requirements to ensure that the correct content type (text/yaml or text/x-yaml)

For example, if you want to serve chart in a directory other than $WEBROOT/charts, make sure there is a charts/ directory in the Web root directory and put the index file and chart in that folder.

Manage chart libraries to store chart in chart libraries

Now that we have a chart repository, let's upload a chart and an index file to the repository. The chart in the chart library must be properly packaged (helm package chart-name/) and version (following the SemVer 2 standard).

The next steps are a sample workflow, and you can use any workflow you like to store and update chart in the chart library.

When you are ready to package chart, create a new directory and move the packaged chart to that directory.

$helm package. $mkdir emqx-charts$ mv emqx-0.1.0.tgz emqx-charts/$ helm repo index emqx-charts-- url https://example.com/charts

The last command takes the path of the local directory you just created and the URL of the remote chart library, and generates index.yaml in the given directory path.

Chart and index files can now be uploaded to the chart library using synchronization tools or manually. If you are using Google cloud storage, use the gsutil client to view this sample workflow. For GitHub, you can simply put the chart into the appropriate target branch.

Add chart to an existing repository

Each time a new chart is added to the repository, the index must be regenerated. The helm repo index command completely rebuilds the file from scratch by index.yaml, but includes only the chart it found locally.

You can use the-merge flag to add a new chart to an existing index.yaml file incrementally (this is a good choice when using a remote repository such as GCS). Run helm repo index-help for more information

Be sure to upload the modified index.yaml file and chart. If the source provenance file is generated, upload it as well.

Share chart with others

When you are ready to share the chart, just let others know what the URL of the repository is.

They will add the repository to their helm client through the helm repo add [NAME] [URL] command and can have a name with any reference to the repository that they want.

$helm repo add emqx-charts https://example.com/charts$ helm repo listemqx-charts https://example.com/charts

If chart is supported by HTTP basic authentication, you can also provide a user name and password here:

$helm repo add emqx-charts https://example.com/charts-username my-username-password my-password$ helm repo listemqx-charts https://example.com/charts

Note: if the repository does not contain a valid repository index.yaml file, the addition will not succeed.

After that, users will be able to search for chart. After updating the repository, they can use the helm repo update command to get the latest chart information.

The principle is that the helm repo add and helm repo update commands take the index.yaml files and store them in the $HELM_HOME/repository/cache/ directory. This is where helm search found information about chart.

References Chart Repository Repository Guide using Helm to manage kubernetes applications Kunbernetes-installation and deployment tool Helm for Container Cloud applications

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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report