helm 部署

Posted fengjian2016

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了helm 部署相关的知识,希望对你有一定的参考价值。

Helm 基本概念

Helm 可以理解为 Kubernetes 的包管理工具,可以方便地发现、共享和使用为Kubernetes构建的应用,它包含几个基本概念

  • Chart:一个 Helm 包,其中包含了运行一个应用所需要的镜像、依赖和资源定义等,还可能包含 Kubernetes 集群中的服务定义,类似 Homebrew 中的 formula,APT 的 dpkg 或者 Yum 的 rpm 文件,
  • Release: 在 Kubernetes 集群上运行的 Chart 的一个实例。在同一个集群上,一个 Chart 可以安装很多次。每次安装都会创建一个新的 release。例如一个 mysql Chart,如果想在服务器上运行两个数据库,就可以把这个 Chart 安装两次。每次安装都会生成自己的 Release,会有自己的 Release 名称。
  • Repository:用于发布和存储 Chart 的仓库。

Helm 组件

Helm 采用客户端/服务器架构,有如下组件组成:

  • Helm CLI 是 Helm 客户端,可以在本地执行
  • Tiller 是服务器端组件,在 Kubernetes 群集上运行,并管理 Kubernetes 应用程序的生命周期
  • Repository 是 Chart 仓库,Helm客户端通过HTTP协议来访问仓库中Chart的索引文件和压缩包。

  

安装步骤

1、 下载helm安装包

wget https://storage.googleapis.com/kubernetes-helm/helm-v2.10.0-rc.3-linux-amd64.tar.gz

2、创建tiller的serviceaccountclusterrolebinding

kubectl create serviceaccount --namespace kube-system tiller
kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller

3. 安装helm服务端tiller

[[email protected] gateway]# helm init -i 192.168.200.10/source/kubernetes-helm/tiller:v2.10.0-rc.3  --service-account tiller --skip-refresh
Creating /root/.helm 
Creating /root/.helm/repository 
Creating /root/.helm/repository/cache 
Creating /root/.helm/repository/local 
Creating /root/.helm/plugins 
Creating /root/.helm/starters 
Creating /root/.helm/cache/archive 
Creating /root/.helm/repository/repositories.yaml 
Adding stable repo with URL: https://kubernetes-charts.storage.googleapis.com 
Adding local repo with URL: http://127.0.0.1:8879/charts 
$HELM_HOME has been configured at /root/.helm.

Tiller (the Helm server-side component) has been installed into your Kubernetes Cluster.

Please note: by default, Tiller is deployed with an insecure allow unauthenticated users policy.
To prevent this, run `helm init` with the --tiller-tls-verify flag.
For more information on securing your installation see: https://docs.helm.sh/using_helm/#securing-your-helm-installation
Happy Helming!

 

4、 查看是否安装

[[email protected] gateway]# kubectl -n kube-system get pods|grep tiller
tiller-deploy-849c444cff-h9zw2 1/1 Running 0 46s

 

5、创建chart

helm  create    gateway

 

6. 测试修改是否正确

[[email protected] helm]# ls
gateway  helm-v2.10.0-rc.3-linux-amd64.tar.gz  linux-amd64
[[email protected] helm]# helm install --dry-run --debug ./gateway

[debug] Created tunnel using local port: 46252

[debug] SERVER: "127.0.0.1:46252"

[debug] Original chart version: ""
[debug] CHART PATH: /root/helm/gateway

NAME:   imprecise-sabertooth
REVISION: 1
RELEASED: Tue Aug 14 14:42:14 2018
CHART: gateway-0.1.0
USER-SUPPLIED VALUES:
{}

COMPUTED VALUES:
affinity: {}
image:
  pullPolicy: IfNotPresent
  repository: 192.168.200.10/source/nginx
  tag: latest
ingress: {}
nodeSelector: {}
replicaCount: 1
resources:
  limits:
    cpu: 100m
    memory: 128Mi
  requests:
    cpu: 100m
    memory: 128Mi
service:
  port: 80
  type: ClusterIP
tolerations: []

HOOKS:
MANIFEST:

---
# Source: gateway/templates/service.yaml
apiVersion: v1
kind: Service
metadata:
  name: imprecise-sabertooth-gateway
  labels:
    app: gateway
    chart: gateway-0.1.0
    release: imprecise-sabertooth
    heritage: Tiller
spec:
  type: ClusterIP
  ports:
    - port: 80
      targetPort: http
      protocol: TCP
      name: http
  selector:
    app: gateway
    release: imprecise-sabertooth
---
# Source: gateway/templates/deployment.yaml
apiVersion: apps/v1beta2
kind: Deployment
metadata:
  name: imprecise-sabertooth-gateway
  labels:
    app: gateway
    chart: gateway-0.1.0
    release: imprecise-sabertooth
    heritage: Tiller
spec:
  replicas: 1
  selector:
    matchLabels:
      app: gateway
      release: imprecise-sabertooth
  template:
    metadata:
      labels:
        app: gateway
        release: imprecise-sabertooth
    spec:
      containers:
        - name: gateway
          image: "192.168.200.10/source/nginx:latest"
          imagePullPolicy: IfNotPresent
          ports:
            - name: http
              containerPort: 80
              protocol: TCP
          livenessProbe:
            httpGet:
              path: /
              port: http
          readinessProbe:
            httpGet:
              path: /
              port: http
          resources:
            limits:
              cpu: 100m
              memory: 128Mi
            requests:
              cpu: 100m
              memory: 128Mi

 

部署到kubernetes

[[email protected] gateway]# helm install .
NAME:   riotous-crab
LAST DEPLOYED: Tue Aug 14 14:43:21 2018
NAMESPACE: default
STATUS: DEPLOYED

RESOURCES:
==> v1/Service
NAME                  TYPE       CLUSTER-IP    EXTERNAL-IP  PORT(S)  AGE
riotous-crab-gateway  ClusterIP  10.254.26.20  <none>       80/TCP   0s

==> v1beta2/Deployment
NAME                  DESIRED  CURRENT  UP-TO-DATE  AVAILABLE  AGE
riotous-crab-gateway  1        1        1           0          0s

==> v1/Pod(related)
NAME                                  READY  STATUS             RESTARTS  AGE
riotous-crab-gateway-fd7465cc8-frcmd  0/1    ContainerCreating  0         0s


NOTES:
1. Get the application URL by running these commands:
  export POD_NAME=$(kubectl get pods --namespace default -l "app=gateway,release=riotous-crab" -o jsonpath="{.items[0].metadata.name}")
  echo "Visit http://127.0.0.1:8080 to use your application"
  kubectl port-forward $POD_NAME 8080:80

 

查看部署的relaese

helm  list

 

删除relaese

 helm delete   gateway

 

打包分享

[[email protected] gateway]# helm  package .
Successfully packaged chart and saved it to: /root/helm/gateway/gateway-0.1.0.tgz

 

chart通过HTTP server方式提供

 helm serve #默认是  127.0.0.1:8879 

可以添加参数
helm serve  --address 192.168.20.171:80

 

以上是关于helm 部署的主要内容,如果未能解决你的问题,请参考以下文章

helm部署mysql

Helm部署的服务如何修改配置

通过 Terraform Helm 提供程序和 Azure DevOps 部署 helm 图表,同时从 ACR 获取 helm 图表

K8s通过Helm部署入门

Jenkins-k8s-helm-harbor-githab-mysql-nfs微服务发布平台实战

kubernetes-部署helm3