Categories
Uncategorized

Helm simplified application deployment using Kubernetes (2)

table of Contents

    Defined Charts

    Use Helm deployment Demo

    Helm common operations command


Defined Charts

Back before “charts” directory, we turn to interpret and make simple changes.

  • Chart.yaml

Configuration example:

apiVersion: v1
appVersion: "1.1"
description: A demo Helm chart for Kubernetes
name: k8sapp
version: 0.1.1

As shown in the above definitions, Chart.yaml Charts for providing metadata associated definitions, such as name, version, file belonging necessary. The main fields are as follows:

Field

Required

Explanation

name

The current name of the Chart

version

version number

apiVersion

chart API version, it has been “v1”

description

 

Chart description

keywords

 

Keyword List

home

 

Project home page URL

kubeVersion

 

Dependent Kubernetes version

sources

 

Source Address List

maintainers

 

Maintainer list by name, email, url composition

engine

 

Template engine name, the default is gotpl, namely go templates

icon

 

Icon Address

appVersion

 

Application Version

deprecated

 

Are Obsolete

tillerVersion

 

Dependent Tiller versions, such as “> 2.0.0.”

 

  • values.yaml and Templates

values.yaml configuration:

# 定义k8sapp的默认配置
fullnameOverride: k8sapp
replicaCount: 1 #副本数
image: #镜像配置
  repository: ccr.ccs.tencentyun.com/magicodes/k8sapp
  tag: latest

pullPolicy: Always # mirrored pulling strategy, Always means always pull in the mirror, IfNotPresent said that if there is no local pull, Never indicates that only the local mirror

service:   #Service配置
  type: NodePort #NodePort服务类型,以便外部访问
  port: 80
secrets: {}
ingress:
  enabled: false    #不配置ingress
#资源限制
resources:
  limits:
    cpu: 1
    memory: 228Mi
  requests:
    cpu: 100m
    memory: 128Mi

As shown in the above example configuration, we have a values.yaml configuration and configuration Deployment Service, the entire configuration is simple and clean, of course, we can configure more, such as ingress and secrets and so on. Then our configuration is how it works? Here is how to configure converted to the corresponding Deployment, Configuration Service like it? We open deployment.yaml template files in the “templates” directory:

apiVersion: apps/v1beta2
kind: Deployment
metadata:
  name: {{ template "k8sapp.fullname" . }}
  labels:
    app: {{ template "k8sapp.name" . }}
    chart: {{ template "k8sapp.chart" . }}
    draft: {{ default "draft-app" .Values.draft }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      app: {{ template "k8sapp.name" . }}
      release: {{ .Release.Name }}
  template:
    metadata:
      labels:
        app: {{ template "k8sapp.name" . }}
        draft: {{ default "draft-app" .Values.draft }}
        release: {{ .Release.Name }}
      annotations:
        buildID: {{ .Values.buildID }}
    spec:
      containers:
        - name: {{ .Chart.Name }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          ports:
            - name: http
              containerPort: 80
              protocol: TCP
          env:
            {{- $root := . }}
            {{- range $ref, $values := .Values.secrets }}
            {{- range $key, $value := $values }}
            - name: {{ $ref }}_{{ $key }}
              valueFrom:
                secretKeyRef:
                  name: {{ template "k8sapp.fullname" $root }}-{{ $ref | lower }}
                  key: {{ $key }}
            {{- end }}
            {{- end }}
          resources:
{{ toYaml .Values.resources | indent 12 }}
    {{- with .Values.imagePullSecrets }}
      imagePullSecrets:
{{ toYaml . | indent 8 }}
    {{- end }}

As indicated above, this is to use a template file Go Deployment template, which is converted by reading “Chart.yaml” and “values.yaml” configuration. The same, service.yaml, ingress.yaml too, and we can write more templates based on their grammar. These templates convert the implementation of “helm install” command.

It is noteworthy that, “. Values” object can be accessed in any configuration values.yaml, if you use this value from the value defined is overwritten. “. Release” target, compared with a predefined value, any template can be used, and can not be overwritten. Wherein the predefined value is used as follows:

name

Explanation

Release.Name

Published resource instance name

Release.Time

Chart Last Published

Release.Namespace

Namespaces

Release.Service

Publishing service name, usually “Tiller”

Release.IsUpgrade

Whether to upgrade the current operation

Release.IsInstall

The current operation is to be installed

Release.Revision

Revision number, from 1 increments

Chart

Correspondence “Chart.yaml”

Files

Access to all the non-template files and non-special file

 

  • requirements.yaml

requirements.yaml used to manage dependencies. E.g:

dependencies:
  - name: apache
    version: 1.2.3
    repository: http://example.com/charts
  - name: mysql
    version: 3.2.1
    repository: http://another.example.com/charts

As shown, common fields as follows:

  • Chart name represents the name;

  • Chart version represents the version;

  • repository represents Chart repository address, note that we also have to use the “helm repo add” command to add the repository address in the local;

  • alias represents the alias;

  • tags are used to specify that only matching Chart is loaded;

  • condition is used to set conditions to load matching Chart;

  • Import-values are used to import multiple values of the child chart.

If you want to have better control over dependencies, we can manually copy the dependent Charts into the app’s Charts directory to clearly express this dependency. For example, WordPress relies on Apache and MySQL, its dependencies in the form of a directory look like this:

 

 

Deploying Demo with Helm

Okay, so much nagging, it’s time to get some practical. Next, we will deploy based on the above cognitive and Demo configuration. The deployment process is as follows:

 

As shown above, let’s start the deployment journey of Helm.

1. Prepare Chart

Chart we are ready, concrete fancy “values.yaml” an example of.

2. Push Chart

Next we pushed to the warehouse. Here, for simplicity, we directly use the free Helm warehouse Tencent cloud Tencent Hub provides. Tencent Hub’s operation is relatively simple, we are here to skip. Next, we add the local repository to:

helm repo add {mycharts} https://hub.tencentyun.com/charts/mycharts --username {myname} --password {mypassword}

“Helm repo add” command is used to add a list of the warehouse to the local repository, the above described command, the variables are as follows:

  • mycharts replace with your own warehouse namespace (user name or organization name)

  • myname replaced with Tencent Hub account username

  • mypassword Replace Tencent Hub account password

After the addition is complete, we can use the command “helm repo list” listed in the local repository list:

 

Next, we need to pack our Chart pushed to Tencent Hub of Helm warehouse, before you push them, we also need to install the plug-push platforms:

yum install git # If a local installed git, you can omit this step

helm plugin install https://

github.com/imroc/helm-push # push plug-in installation Tencent Hub

After the plug-in installed, we can start up our operation. First, make sure Chart file on the client machine where Helm ready, as shown in the “k8sapp” directory:

 

Then you can execute the push command:

helm push ./k8sapp xinlai

As indicated above, “helm push” to push Chart, “./ k8sapp” is a directory location, “xinlai” is the name of the repository. Implementation of the above script will automatically packaged and push the target directory:

 

Next, we can see on our Tencent Hub Management Interface package:

 

Not only that, we can see the details:

  1. Pull the deployment and implementation of

If you are deploying Helm applications on a k8s cluster in the cloud, the operation is very simple, and the cloud supply basically provides packages:

 

Once created as follows:

 

As shown above, this application Helm resources and create a Deployment Service resource, which is the type of Service NodePort, the port is “32160”, then we can access through node ports:

 

If local cluster it? We can pull Chart deploy and execute the following script:

helm repo update && helm fetch xinlai/k8sapp
helm install xinlai/k8sapp

After complete deployment shown in FIG:

 

Note: We can deploy a specific version of the application by Helm “–version” argument:

 

As shown, we get Service port is “32705”, the same node as shown by the local port access:

 

At this point, we Helm deployed by a simple “k8sapp” Demo application. After the deployment is complete, we can command “helm list” to see the Release deployed:

 

 

Helm common operations command

In addition to the above-mentioned command number of Helm, Demo common operations as follows:

  • Upgrades and updates

helm upgrade zeroed-rodent xinlai/k8sapp –version 0.1.6

# “Zeroed-rodent” is Release name, “xinlai / k8sapp” for the Chart address.

 

helm upgrade –set imageTag=20190731075922 zeroed-rodent xinlai/k8sapp

# Update image

 

  • View Version History

helm history zeroed-rodent

#查看Release历史

 

  • Rollback

helm rollback zeroed-rodent 1

#回滚到版本1

 

  • delete

helm delete zeroed-rodent

#删除Release

 

  • Download Chart

helm fetch xinlai/k8sapp

#下载Chart

 

  • Deploy Based on Local Chart Directory

helm install ./k8sapp

# Directory-based “k8sapp” deployment

 

  • Bale

helm package ./k8sapp

# Will generate a compressed package similar to “/k8sapp-0.1.5.tgz” file

 

  • search for

helm search k8sapp

# Search in all warehouses Chart “k8sapp”

 

  • Start local warehousing services

helm serve

# Default address is “127.0.0.1:8879”, you can use the “–address” parameter binding other addresses and ports

 

 

Past content links

Docker + Kubernetes has become the mainstream cloud computing (XXV)

After the clouds container of how to save costs? (Twenty-six)

Learn Kubernetes main structure (xxvii)

Use Minikube deploy local Kubernetes cluster (28)

Use kubectl management k8s cluster (29)

Use Kubeadm create a cluster of k8s deployment plan (thirty)

Use Kubeadm create a cluster of nodes deployed k8s (31)

Handling Ideas for Cluster Failures and Health Status Checks (32)

Handling of cluster fault handling and auscultation triplet axe (33)

Import and export generic open source library released Magicodes.ExporterAndImporter

Deploy an app using Kubectl

Access apps through Service (1)

Access apps through Service (2)

Ingress to use micro load distribution service

Helm Kubernetes simplified application deployment using (1)

Leave a Reply