溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

helm的部署和簡(jiǎn)單使用

發(fā)布時(shí)間:2021-08-25 16:39:04 來源:億速云 閱讀:366 作者:chen 欄目:云計(jì)算

本篇內(nèi)容主要講解“helm的部署和簡(jiǎn)單使用”,感興趣的朋友不妨來看看。本文介紹的方法操作簡(jiǎn)單快捷,實(shí)用性強(qiáng)。下面就讓小編來帶大家學(xué)習(xí)“helm的部署和簡(jiǎn)單使用”吧!

Helm通過軟件打包的形式,支持發(fā)布的版本管理和控制,很大程度上簡(jiǎn)化了Kubernetes應(yīng)用部署和管理的復(fù)雜性。

隨著業(yè)務(wù)容器化與向微服務(wù)架構(gòu)轉(zhuǎn)變,通過分解巨大的單體應(yīng)用為多個(gè)服務(wù)的方式,分解了單體應(yīng)用的復(fù)雜性,使每個(gè)微服務(wù)都可以獨(dú)立部署和擴(kuò)展,實(shí)現(xiàn)了敏捷開發(fā)和快速迭代和部署。但任何事情都有兩面性,雖然微服務(wù)給我們帶來了很多便利,但由于應(yīng)用被拆分成多個(gè)組件,導(dǎo)致服務(wù)數(shù)量大幅增加,對(duì)于Kubernetest編排來說,每個(gè)組件有自己的資源文件,并且可以獨(dú)立的部署與伸縮,這給采用Kubernetes做應(yīng)用編排帶來了諸多挑戰(zhàn)

  1. 管理、編輯與更新大量的K8s配置文件

  2. 部署一個(gè)含有大量配置文件的復(fù)雜K8s應(yīng)用

  3. 分享和復(fù)用K8s配置和應(yīng)用

  4. 參數(shù)化配置模板支持多個(gè)環(huán)境

  5. 管理應(yīng)用的發(fā)布:回滾、diff和查看發(fā)布?xì)v史

  6. 控制一個(gè)部署周期中的某一些環(huán)節(jié)

  7. 發(fā)布后的驗(yàn)證

而Helm恰好可以幫助我們解決上面問題。

Helm把Kubernetes資源(比如deployments、services或 ingress等) 打包到一個(gè)chart中,而chart被保存到chart倉庫。通過chart倉庫來存儲(chǔ)和分享chart。Helm使發(fā)布可配置,支持發(fā)布應(yīng)用配置的版本管理,簡(jiǎn)化了Kubernetes部署應(yīng)用的版本控制、打包、發(fā)布、刪除、更新等操作。

本文簡(jiǎn)單介紹了Helm的用途、架構(gòu)、安裝和使用。

用途

做為Kubernetes的一個(gè)包管理工具,Helm具有如下功能:

  • 創(chuàng)建新的chart

  • chart打包成tgz格式

  • 上傳chart到chart倉庫或從倉庫中下載chart

  • 在Kubernetes集群中安裝或卸載chart

  • 管理用Helm安裝的chart的發(fā)布周期

Helm有三個(gè)重要概念:

  1. chart:包含了創(chuàng)建Kubernetes的一個(gè)應(yīng)用實(shí)例的必要信息

  2. config:包含了應(yīng)用發(fā)布配置信息

  3. release:是一個(gè)chart及其配置的一個(gè)運(yùn)行實(shí)例

架構(gòu)

helm的部署和簡(jiǎn)單使用

組件

Helm有以下兩個(gè)組成部分:

  1. Helm Client是用戶命令行工具,其主要負(fù)責(zé)如下:

    • 本地chart開發(fā)

    • 倉庫管理

    • 與Tiller sever交互

    • 發(fā)送預(yù)安裝的chart

    • 查詢r(jià)elease信息

    • 要求升級(jí)或卸載已存在的release

  2. Tiller server是一個(gè)部署在Kubernetes集群內(nèi)部的server,其與Helm client、Kubernetes API server進(jìn)行交互,主要負(fù)責(zé)如下:

    • 監(jiān)聽來自Helm client的請(qǐng)求

    • 通過chart及其配置構(gòu)建一次發(fā)布

    • 安裝chart到Kubernetes集群,并跟蹤隨后的發(fā)布

    • 通過與Kubernetes交互升級(jí)或卸載chart

簡(jiǎn)單的說,client管理charts,而server管理發(fā)布release。

實(shí)現(xiàn)

  1. Helm client

    • Helm client采用go語言編寫,采用gRPC協(xié)議與Tiller server交互。

  2. Helm server

    • Tiller server也同樣采用go語言編寫,提供了gRPC server與helm client進(jìn)行交互,利用Kubernetes client 庫與Kubernetes進(jìn)行通信,當(dāng)前庫使用了REST+JSON格式。

    • Tiller server 沒有自己的數(shù)據(jù)庫,目前使用Kubernetes的ConfigMaps存儲(chǔ)相關(guān)信息

說明:配置文件盡可能使用YAM格式

安裝

如果與我的情況不同,請(qǐng)閱讀官方的quick guide,了安裝的核心流程和多種情況。

Helm Release地址

前置條件

  1. kubernetes集群

  2. 了解kubernetes的Context安全機(jī)制

  3. 下載helm的安裝包wget https://storage.googleapis.com/kubernetes-helm/helm-v2.11.0-linux-amd64.tar.gz

配置ServiceAccount和規(guī)則

我的環(huán)境使用了RBAC(Role-Based Access Control )的授權(quán)方式,需要先配置ServiceAccount和規(guī)則,然后再安裝helm。官方配置參考Role-based Access Control文檔。

配置helm全集群權(quán)限

權(quán)限管理yml:

apiVersion: v1
kind: ServiceAccount
metadata:
  name: tiller
  namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: tiller
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: cluster-admin
subjects:
  - kind: ServiceAccount
    name: tiller
    namespace: kube-system

cluster-admin 是kubernetes默認(rèn)創(chuàng)建的角色。不需要重新定義。

安裝helm:

$ kubectl create -f rbac-config.yaml
serviceaccount "tiller" created
clusterrolebinding "tiller" created
$ helm init --service-account tiller

運(yùn)行結(jié)果:

$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!

實(shí)驗(yàn)環(huán)境建議使用本方式安裝,然后安裝ingress-nginx等系統(tǒng)組件。

配置helm在一個(gè)namespace,管理另一個(gè)namespace

配置helm 安裝在helm-system namespace,允許Tiller發(fā)布應(yīng)用到kube-public namespace。

創(chuàng)建Tiller安裝namespace 和 ServiceAccount

創(chuàng)建helm-system namespace,使用命令kubectl create namespace helm-system

定義ServiceAccount

---
kind: ServiceAccount
apiVersion: v1
metadata:
  name: tiller
  namespace: helm-system
Tiller管理namespace的角色和權(quán)限配置

創(chuàng)建一個(gè)Role,擁有namespace kube-public的所有權(quán)限。將Tiller的ServiceAccount綁定到這個(gè)角色上,允許Tiller 管理kube-public namespace 所有的資源。

---
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: tiller-manager
  namespace: kube-public
rules:
- apiGroups: ["", "extensions", "apps"]
  resources: ["*"]
  verbs: ["*"]

---
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: tiller-binding
  namespace: kube-public
subjects:
- kind: ServiceAccount
  name: tiller
  namespace: helm-system
roleRef:
  kind: Role
  name: tiller-manager
  apiGroup: rbac.authorization.k8s.io
Tiller內(nèi)部的Release信息管理

Helm中的Release信息存儲(chǔ)在Tiller安裝的namespace中的ConfigMap,即helm-system,需要允許Tiller操作helm-systemConfigMap。所以創(chuàng)建Role helm-system.tiller-manager,并綁定到ServiceAccounthelm-system.tiller

---
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  namespace: helm-system
  name: tiller-manager
rules:
- apiGroups: ["", "extensions", "apps"]
  resources: ["configmaps"]
  verbs: ["*"]

---
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: tiller-binding
  namespace: helm-system
subjects:
- kind: ServiceAccount
  name: tiller
  namespace: helm-system
roleRef:
  kind: Role
  name: tiller-manager
  apiGroup: rbac.authorization.k8s.io
init helm
使用命令`helm init --service-account tiller --tiller-namespace helm-system`安裝helm。

helm init 參數(shù)說明:

  • --service-account:指定helm Tiller的ServiceAccount,對(duì)于啟用了kubernetesRBAC的集群適用。

  • --tiller-namespace:將helm 安裝到指定的namespace中;

  • --tiller-image:指定helm鏡像

  • --kube-context:將helm Tiller安裝到特定的kubernetes集群中;

第一次運(yùn)行出現(xiàn)問題:

[root@kuber24 helm]# helm init --service-account tiller --tiller-namespace helm-system
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
Error: Looks like "https://kubernetes-charts.storage.googleapis.com" is not a valid chart repository or cannot be reached: Get https://kubernetes-charts.storage.googleapis.com/index.yaml: EOF

這個(gè)是由于google的都被墻了,修改Hosts,指定storage.googleapis.com對(duì)應(yīng)的課訪問的IP即可。最新的國內(nèi)可訪問google的Hosts配置見github項(xiàng)目googlehosts/hosts的hosts/hosts-files/hosts文件。

再次運(yùn)行init helm命令,成功安裝。

[root@kuber24 helm]# helm init --service-account tiller --tiller-namespace helm-system
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!

查看Tiller的Pod狀態(tài)時(shí),發(fā)現(xiàn)Pod出現(xiàn)錯(cuò)誤ImagePullBackOff,如下:

[root@kuber24 resources]# kubectl get pods --all-namespaces|grep tiller
helm-system   tiller-deploy-cdcd5dcb5-fqm57          0/1     ImagePullBackOff   0          13m

查看pod的詳細(xì)信息kubectl describe pod tiller-deploy-cdcd5dcb5-fqm57 -n helm-system,發(fā)現(xiàn)Pod依賴鏡像gcr.io/kubernetes-helm/tiller:v2.11.0。

查詢docker hub上是否有人復(fù)制過改鏡像,如圖:

[root@kuber24 ~]# docker search tiller:v2.11.0
INDEX       NAME                          DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
docker.io   docker.io/jay1991115/tiller   gcr.io/kubernetes-helm/tiller:v2.11.0           1                    [OK]
docker.io   docker.io/luyx30/tiller       tiller:v2.11.0                                  1                    [OK]
docker.io   docker.io/1017746640/tiller   FROM gcr.io/kubernetes-helm/tiller:v2.11.0      0                    [OK]
docker.io   docker.io/724399396/tiller    gcr.io/kubernetes-helm/tiller:v2.11.0-rc.2...   0                    [OK]
docker.io   docker.io/fengzos/tiller      gcr.io/kubernetes-helm/tiller:v2.11.0           0                    [OK]
docker.io   docker.io/imwower/tiller      tiller from gcr.io/kubernetes-helm/tiller:...   0                    [OK]
docker.io   docker.io/xiaotech/tiller     FROM gcr.io/kubernetes-helm/tiller:v2.11.0      0                    [OK]
docker.io   docker.io/yumingc/tiller      tiller:v2.11.0                                  0                    [OK]
docker.io   docker.io/zhangc476/tiller    gcr.io/kubernetes-helm/tiller/kubernetes-h...   0                    [OK]

同樣使用hub.docker.commirrorgooglecontainers加速的google鏡像,然后改鏡像的名字。每個(gè)Node節(jié)點(diǎn)都需要安裝。

安裝問題

鏡像問題

鏡像下載不下來:使用他人同步到docker hub上面的鏡像;使用docker search $NAME:$VERSION

安裝helm提示repo連接不上

使用Hosts翻墻實(shí)現(xiàn)。

下載Chart問題

問題提示:

[root@kuber24 ~]# helm install nginx --tiller-namespace helm-system --namespace kube-public
Error: failed to download "nginx" (hint: running `helm repo update` may help)

使用helm repo update 后,并沒有解決問題。

如下:

[root@kuber24 ~]# helm install nginx --tiller-namespace helm-system --namespace kube-public
Error: failed to download "nginx" (hint: running `helm repo update` may help)
[root@kuber24 ~]# helm repo update
Hang tight while we grab the latest from your chart repositories...
...Skip local chart repository
...Successfully got an update from the "stable" chart repository
Update Complete. ? Happy Helming!?
[root@kuber24 ~]# helm install nginx --tiller-namespace helm-system --namespace kube-public
Error: failed to download "nginx" (hint: running `helm repo update` may help)

可能的原因:

  1. 沒有nginx這個(gè)chart:使用helm search nginx 查詢nginx chart信息。

  2. 網(wǎng)絡(luò)連接問題,下載不了。這種情況下,等待一定超時(shí)后,helm會(huì)提示。

使用

添加常見的repo

添加aliyun, github 和官方incubator charts repository。

helm add repo gitlab https://charts.gitlab.io/
helm repo add aliyun https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts
helm repo add incubator https://kubernetes-charts-incubator.storage.googleapis.com/

日常使用

本小結(jié)的$NAME表示helm的repo/chart_name。

  1. 查詢charts: helm search $NAME

  2. 查看release的列表:helm ls [--tiller-namespace $TILLER_NAMESPACE]

  3. 查詢package 信息: helm inspect $NAME

  4. 查詢package支持的選項(xiàng):helm inspect values $NAME

  5. 部署chart:helm install $NAME [--tiller-namespace $TILLER_NAMESPACE] [--namespace $CHART_DEKPLOY_NAMESPACE]

  6. 刪除release:helm delete $RELEASE_NAME [--purge] [--tiller-namespace $TILLER_NAMESPACE]

  7. 更新:helm upgrade --set $PARAM_NAME=$PARAM_VALUE $RELEASE_NAME $NAME [--tiller-namespace $TILLER_NAMESPACE]

  8. 回滾:helm rollback $RELEASE_NAME $REVERSION [--tiller-namespace $TILLER_NAMESPACE]

刪除release時(shí),不使用--purge參數(shù),會(huì)僅撤銷pod部署,不會(huì)刪除release的基本信息,不能release同名的chart。

部署RELEASE

部署mysql時(shí),查詢參數(shù)并配置相應(yīng)的參數(shù)。

查詢可配置的參數(shù):

[root@kuber24 charts]# helm inspect values aliyun/mysql
## mysql image version
## ref: https://hub.docker.com/r/library/mysql/tags/
##
image: "mysql"
imageTag: "5.7.14"

## Specify password for root user
##
## Default: random 10 character string
# mysqlRootPassword: testing

## Create a database user
##
# mysqlUser:
# mysqlPassword:

## Allow unauthenticated access, uncomment to enable
##
# mysqlAllowEmptyPassword: true

## Create a database
##
# mysqlDatabase:

## Specify an imagePullPolicy (Required)
## It's recommended to change this to 'Always' if the image tag is 'latest'
## ref: http://kubernetes.io/docs/user-guide/images/#updating-images
##
imagePullPolicy: IfNotPresent

livenessProbe:
  initialDelaySeconds: 30
  periodSeconds: 10
  timeoutSeconds: 5
  successThreshold: 1
  failureThreshold: 3

readinessProbe:
  initialDelaySeconds: 5
  periodSeconds: 10
  timeoutSeconds: 1
  successThreshold: 1
  failureThreshold: 3

## Persist data to a persistent volume
persistence:
  enabled: true
  ## database data Persistent Volume Storage Class
  ## If defined, storageClassName: <storageClass>
  ## If set to "-", storageClassName: "", which disables dynamic provisioning
  ## If undefined (the default) or set to null, no storageClassName spec is
  ##   set, choosing the default provisioner.  (gp2 on AWS, standard on
  ##   GKE, AWS & OpenStack)
  ##
  # storageClass: "-"
  accessMode: ReadWriteOnce
  size: 8Gi

## Configure resource requests and limits
## ref: http://kubernetes.io/docs/user-guide/compute-resources/
##
resources:
  requests:
    memory: 256Mi
    cpu: 100m

# Custom mysql configuration files used to override default mysql settings
configurationFiles:
#  mysql.cnf: |-
#    [mysqld]
#    skip-name-resolve


## Configure the service
## ref: http://kubernetes.io/docs/user-guide/services/
service:
  ## Specify a service type
  ## ref: https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services---service-types
  type: ClusterIP
  port: 3306
  # nodePort: 32000

例如我們需要配置mysql的root密碼,那么可以直接使用--set參數(shù)設(shè)置選項(xiàng),例如roo密碼設(shè)置:--set mysqlRootPassword=hgfgood。

通過mysql選項(xiàng)的說明中persistence參數(shù),可以看出mysql 需要持久化存儲(chǔ),所以需要給kubernetes配置持久化存儲(chǔ)卷PV。

創(chuàng)建PV:

[root@kuber24 resources]# cat local-pv.yml
apiVersion: v1
kind: PersistentVolume
metadata:
  name: local-pv
  namespace: kube-public
spec:
  capacity:
    storage: 30Gi
  accessModes:
    - ReadWriteOnce
  persistentVolumeReclaimPolicy: Recycle
  hostPath:
    path: /home/k8s

完整的release chart命令如下:helm install --name mysql-dev --set mysqlRootPassword=hgfgood aliyun/mysql --tiller-namespace helm-system --namespace kube-public

查看已經(jīng)release的chart列表:

[root@kuber24 charts]# helm ls --tiller-namespace=helm-system
NAME     	REVISION	UPDATED                 	STATUS  	CHART      	APP VERSION	NAMESPACE
mysql-dev	1       	Fri Oct 26 10:35:55 2018	DEPLOYED	mysql-0.3.5	           	kube-public

正常情況下,dashboard監(jiān)控的情況如下圖:

helm的部署和簡(jiǎn)單使用

運(yùn)行此mysql chart 需要busybox鏡像,偶爾會(huì)出現(xiàn)下圖所示的問題,這是docker默認(rèn)訪問國外的docker hub導(dǎo)致的。需要先下載busybox鏡像。

helm的部署和簡(jiǎn)單使用

更新和回滾

上例中,安裝完mysql,使用的root密碼為hgfgood。本例中將其更新為hgf然后回滾到原始的密碼hgfgood

查詢mysql安裝后的密碼:

[root@kuber24 charts]# kubectl get secret --namespace kube-public mysql-dev-mysql -o jsonpath="{.data.mysql-root-password}" | base64 --decode; echo
hgfgood

更新mysql的root密碼,helm upgrade --set mysqlRootPassword=hgf mysql-dev mysql --tiller-namespace helm-system

更新完成后再次查詢mysql的root用戶密碼

[root@kuber24 charts]# kubectl get secret --namespace kube-public mysql-dev-mysql -o jsonpath="{.data.mysql-root-password}" | base64 --decode; echo
hgf

查看RELEASE的信息:

[root@kuber24 charts]# helm ls --tiller-namespace helm-system
NAME     	REVISION	UPDATED                 	STATUS  	CHART      	APP VERSION	NAMESPACE
mysql-dev	2       	Fri Oct 26 11:26:48 2018	DEPLOYED	mysql-0.3.5	           	kube-public

查看REVISION,可以目前mysql-dev有兩個(gè)版本。

回滾到版本1

[root@kuber24 charts]# helm rollback mysql-dev 1 --tiller-namespace helm-system
Rollback was a success! Happy Helming!
[root@kuber24 charts]# kubectl get secret --namespace kube-public mysql-dev-mysql -o jsonpath="{.data.mysql-root-password}" | base64 --decode; echo
hgfgood

通過上述輸出可以發(fā)現(xiàn)RELEASE已經(jīng)回滾。

常見問題

  1. Error: could not find tiller,使用helm client,需要與tiller 交互時(shí),需要制定tiller的namespace,使用參數(shù)--tiller-namespace helm-system,此參數(shù)默認(rèn)時(shí)kube-system。

境內(nèi)chart下載失敗的問題

由于網(wǎng)絡(luò)問題下載會(huì)失敗的問題,例如:

[root@kuber24 ~]# helm install stable/mysql --tiller-namespace helm-system --namespace kube-public  --debug
[debug] Created tunnel using local port: '32774'

[debug] SERVER: "127.0.0.1:32774"

[debug] Original chart version: ""
Error: Get https://kubernetes-charts.storage.googleapis.com/mysql-0.10.2.tgz: read tcp 10.20.13.24:56594->216.58.221.240:443: read: connection reset by peer
  1. 進(jìn)入本地charts保存的目錄

  2. 使用阿里云fetch對(duì)應(yīng)的chart

例如 安裝mysql。

helm fetch aliyun/mysql --untar
[root@kuber24 charts]# ls
mysql
[root@kuber24 charts]# ls mysql/
Chart.yaml  README.md  templates  values.yaml

然后再次運(yùn)行helm install 安裝mysql chart。

helm install mysql --tiller-namespace helm-system --namespace kube-public

可以使用--debug參數(shù),打開debug信息。

[root@kuber24 charts]# helm install mysql --tiller-namespace helm-system --namespace kube-public --debug
[debug] Created tunnel using local port: '41905'

[debug] SERVER: "127.0.0.1:41905"

[debug] Original chart version: ""
[debug] CHART PATH: /root/Downloads/charts/mysql

NAME:   kissable-bunny
REVISION: 1
RELEASED: Thu Oct 25 20:20:23 2018
CHART: mysql-0.3.5
USER-SUPPLIED VALUES:
{}

COMPUTED VALUES:
configurationFiles: null
image: mysql
imagePullPolicy: IfNotPresent
imageTag: 5.7.14
livenessProbe:
  failureThreshold: 3
  initialDelaySeconds: 30
  periodSeconds: 10
  successThreshold: 1
  timeoutSeconds: 5
persistence:
  accessMode: ReadWriteOnce
  enabled: true
  size: 8Gi
readinessProbe:
  failureThreshold: 3
  initialDelaySeconds: 5
  periodSeconds: 10
  successThreshold: 1
  timeoutSeconds: 1
resources:
  requests:
    cpu: 100m
    memory: 256Mi
service:
  port: 3306
  type: ClusterIP

HOOKS:
MANIFEST:

---
# Source: mysql/templates/secrets.yaml
apiVersion: v1
kind: Secret
metadata:
  name: kissable-bunny-mysql
  labels:
    app: kissable-bunny-mysql
    chart: "mysql-0.3.5"
    release: "kissable-bunny"
    heritage: "Tiller"
type: Opaque
data:

  mysql-root-password: "TzU5U2tScHR0Sg=="


  mysql-password: "RGRXU3Ztb3hQNw=="
---
# Source: mysql/templates/pvc.yaml
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: kissable-bunny-mysql
  labels:
    app: kissable-bunny-mysql
    chart: "mysql-0.3.5"
    release: "kissable-bunny"
    heritage: "Tiller"
spec:
  accessModes:
    - "ReadWriteOnce"
  resources:
    requests:
      storage: "8Gi"
---
# Source: mysql/templates/svc.yaml
apiVersion: v1
kind: Service
metadata:
  name: kissable-bunny-mysql
  labels:
    app: kissable-bunny-mysql
    chart: "mysql-0.3.5"
    release: "kissable-bunny"
    heritage: "Tiller"
spec:
  type: ClusterIP
  ports:
  - name: mysql
    port: 3306
    targetPort: mysql
  selector:
    app: kissable-bunny-mysql
---
# Source: mysql/templates/deployment.yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: kissable-bunny-mysql
  labels:
    app: kissable-bunny-mysql
    chart: "mysql-0.3.5"
    release: "kissable-bunny"
    heritage: "Tiller"
spec:
  template:
    metadata:
      labels:
        app: kissable-bunny-mysql
    spec:
      initContainers:
      - name: "remove-lost-found"
        image: "busybox:1.25.0"
        imagePullPolicy: "IfNotPresent"
        command:  ["rm", "-fr", "/var/lib/mysql/lost+found"]
        volumeMounts:
        - name: data
          mountPath: /var/lib/mysql
      containers:
      - name: kissable-bunny-mysql
        image: "mysql:5.7.14"
        imagePullPolicy: "IfNotPresent"
        resources:
          requests:
            cpu: 100m
            memory: 256Mi

        env:
        - name: MYSQL_ROOT_PASSWORD
          valueFrom:
            secretKeyRef:
              name: kissable-bunny-mysql
              key: mysql-root-password
        - name: MYSQL_PASSWORD
          valueFrom:
            secretKeyRef:
              name: kissable-bunny-mysql
              key: mysql-password
        - name: MYSQL_USER
          value: ""
        - name: MYSQL_DATABASE
          value: ""
        ports:
        - name: mysql
          containerPort: 3306
        livenessProbe:
          exec:
            command:
            - sh
            - -c
            - "mysqladmin ping -u root -p${MYSQL_ROOT_PASSWORD}"
          initialDelaySeconds: 30
          periodSeconds: 10
          timeoutSeconds: 5
          successThreshold: 1
          failureThreshold: 3
        readinessProbe:
          exec:
            command:
            - sh
            - -c
            - "mysqladmin ping -u root -p${MYSQL_ROOT_PASSWORD}"
          initialDelaySeconds: 5
          periodSeconds: 10
          timeoutSeconds: 1
          successThreshold: 1
          failureThreshold: 3
        volumeMounts:
        - name: data
          mountPath: /var/lib/mysql
      volumes:
      - name: data
        persistentVolumeClaim:
          claimName: kissable-bunny-mysql
LAST DEPLOYED: Thu Oct 25 20:20:23 2018
NAMESPACE: kube-public
STATUS: DEPLOYED

RESOURCES:
==> v1/Pod(related)
NAME                                  READY  STATUS   RESTARTS  AGE
kissable-bunny-mysql-c7df69d65-lmjzn  0/1    Pending  0         0s

==> v1/Secret

NAME                  AGE
kissable-bunny-mysql  1s

==> v1/PersistentVolumeClaim
kissable-bunny-mysql  1s

==> v1/Service
kissable-bunny-mysql  1s

==> v1beta1/Deployment
kissable-bunny-mysql  1s


NOTES:
MySQL can be accessed via port 3306 on the following DNS name from within your cluster:
kissable-bunny-mysql.kube-public.svc.cluster.local

To get your root password run:

    MYSQL_ROOT_PASSWORD=$(kubectl get secret --namespace kube-public kissable-bunny-mysql -o jsonpath="{.data.mysql-root-password}" | base64 --decode; echo)

To connect to your database:

1. Run an Ubuntu pod that you can use as a client:

    kubectl run -i --tty ubuntu --image=ubuntu:16.04 --restart=Never -- bash -il

2. Install the mysql client:

    $ apt-get update && apt-get install mysql-client -y

3. Connect using the mysql cli, then provide your password:
    $ mysql -h kissable-bunny-mysql -p

To connect to your database directly from outside the K8s cluster:
    MYSQL_HOST=127.0.0.1
    MYSQL_PORT=3306

    # Execute the following commands to route the connection:
    export POD_NAME=$(kubectl get pods --namespace kube-public -l "app=kissable-bunny-mysql" -o jsonpath="{.items[0].metadata.name}")
    kubectl port-forward $POD_NAME 3306:3306

    mysql -h ${MYSQL_HOST} -P${MYSQL_PORT} -u root -p${MYSQL_ROOT_PASSWORD}
打包Chart
  • [ ] 詳細(xì)的打包實(shí)驗(yàn)。

# 創(chuàng)建一個(gè)新的 chart
helm create hello-chart

# validate chart
helm lint

# 打包 chart 到 tgz
helm package hello-chart

到此,相信大家對(duì)“helm的部署和簡(jiǎn)單使用”有了更深的了解,不妨來實(shí)際操作一番吧!這里是億速云網(wǎng)站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI