1. 安装helm package

https://github.com/helm/helm/blob/master/LICENSE

2. 将 helm 配置到环境变量

3. 使用helm的前提是安装了kubectl

4. 使用命令查看kubectl集群配置

如下所示表示与集群的通信正常(如果提示集群不可访问,可根据博文设置:https://www.cnblogs.com/miaoying/p/11193621.html

$ kubectl cluster-info
Kubernetes master is running at https://192.168.1.164:6443
KubeDNS is running at https://192.168.1.164:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
kubernetes-dashboard is running at https://192.168.1.164:6443/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:https/proxy To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.

5. 查看k8s的client, server两端版本是否一致

$ kubectl version
Client Version: version.Info{Major:"", Minor:"", GitVersion:"v1.10.3", GitCommit:"2bba0127d85d5a46ab4b778548be28623b32d0b0", GitTreeState:"clean", BuildDate:"2018-05-21T09:17:39Z", GoVersion:"go1.9.3", Compiler:"gc", Platform:"windows/amd64"}
Server Version: version.Info{Major:"", Minor:"", GitVersion:"v1.15.0", GitCommit:"e8462b5b5dc2584fdcd18e6bcfe9f1e4d970a529", GitTreeState:"clean", BuildDate:"2019-06-19T16:32:14Z", GoVersion:"go1.12.5", Compiler:"gc", Platform:"linux/amd64"}

一开始我的client端版本是1.10.3的,server端的是1.15.0的,导致本地使用helm install包时一直抛异常,比如:

Error: release config failed: Deployment in version "v1beta1" cannot be handled as a Deployment: v1beta1.Deployment.Status: v1beta1.DeploymentStatus.Conditions: []v1beta1.DeploymentCondition: v1beta1.DeploymentCondition.Status: ReadString: expects " or n, but found t, error found in #10 byte of ...|"status":true,"type"|..., bigger context ...|ty","reason":"MinimumReplicasAvailable","status":true,"type":"Available"}],"observedGeneration":,"r|...

原因是client端的版本与server端的不一致,导致两个端对配置文件的理解不一样,且有些配置属性低版本的不支持。

6. 将client、server端的版本升级成一致的:1.15.0

下载该版本的client端

https://dl.k8s.io/v1.15.0/kubernetes-client-windows-amd64.tar.gz

查看kubectl位置

$ which kubectl
/c/Program Files/Docker/Docker/Resources/bin/kubectl

发现kubectl在docker里(由于我的kubectl工具是安装docker for windows 时自带的,内置在docker里面)

为了使每次使用kubectl时,能够用1.15.0版本的,需要在环境变量里面对kubectl重新进行配置,我是直接配置在系统环境变量的Path里面,且将它的位置上移到最前面

另开一个终端,再次查看kubectl的位置,如下所示:

$ which kubectl
/f/kubernetes/install-1.15./kubectl

查看kubectl的版本信息(此时的版本信息是统一的了)

$ kubectl version
Client Version: version.Info{Major:"", Minor:"", GitVersion:"v1.15.0", GitCommit:"e8462b5b5dc2584fdcd18e6bcfe9f1e4d970a529", GitTreeState:"clean", BuildDate:"2019-06-19T16:40:16Z", GoVersion:"go1.12.5", Compiler:"gc", Platform:"windows/amd64"}
Server Version: version.Info{Major:"", Minor:"", GitVersion:"v1.15.0", GitCommit:"e8462b5b5dc2584fdcd18e6bcfe9f1e4d970a529", GitTreeState:"clean", BuildDate:"2019-06-19T16:32:14Z", GoVersion:"go1.12.5", Compiler:"gc", Platform:"linux/amd64"}

7. 查看当前kubernetes上下文

$ kubectl config current-context
kubernetes-admin@kubernetes

8. 初始化helm且安装tiller

helm init

由于 Helm 默认会去 storage.googleapis.com 拉取镜像,如果你当前执行的机器不能访问该域名的话可以使用以下命令来安装

helm init --client-only --stable-repo-url https://aliacs-app-catalog.oss-cn-hangzhou.aliyuncs.com/charts/
helm repo add incubator https://aliacs-app-catalog.oss-cn-hangzhou.aliyuncs.com/charts-incubator/
helm repo update

创建服务端

helm init --service-account tiller --upgrade -i registry.cn-hangzhou.aliyuncs.com/google_containers/tiller:v2.14.2  --stable-repo-url https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts

查看tiller

$ kubectl -n kube-system get pods|grep tiller
tiller-deploy-6bb85c7cb7-jhr65 / Running 34h

9. 构建一个chart

我构建的chart的目录结构如下:

|-- dateway
|---- templates # 【可选】 部署文件模板目录,模板使用的值来自values.yaml和tiller提供的值
|-----|-- deployment.yaml
|---- Charts.yaml # yaml文件,用于描述chart的基本信息,包括名字版本等
|---- values.yaml # chart的默认配置文件

配置服务charts文件(注意yaml文件格式),可通过拉取原先已有的部署项目的配置文件:比如我是拉取curl的配置文件作为样例 kubectl get Deployment curl -o yaml > curl.yaml

(yaml格式是否合法,可通过 http://www.bejson.com/validators/yaml_editor/ 进行检验)

deployment.yaml

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
annotations:
deployment.kubernetes.io/revision: ""
creationTimestamp: --15T09::17Z
generation:
labels:
app: gateway
name: gateway
namespace: rubikt
resourceVersion: ""
selfLink: /apis/extensions/v1beta1/namespaces/rubikt/deployments/gateway
uid: a0ca862b-4a12-11e9-80d3-0050569b47c5
spec:
progressDeadlineSeconds:
replicas:
revisionHistoryLimit:
selector:
matchLabels:
app: gateway
strategy:
rollingUpdate:
maxSurge: %
maxUnavailable: %
type: RollingUpdate
template:
metadata:
creationTimestamp: null
labels:
app: gateway
spec:
containers:
- image: 192.168.2.50/health/gateway:1.5.-SNAPSHOT
ports:
- {containerPort: , protocol: TCP}
env:
- {name: JAVA_OPTS, value: '-Denv=dev -Ddev_meta=http://apollo.dev.zwjk.com -Dapp.id=health-gateway -server -Xmx768m'}
- {name: CONSUL_URL, value: 10.109.36.166}
- {name: CONSUL_HOST, value: 10.100.39.12}
- {name: CONSUL_PORT, value: ''}
terminationMessagePath: /dev/termination-log
name: gateway
resources:
limits:
cpu: 200m
memory: 768Mi
requests:
cpu: 50m
memory: 512Mi
dnsPolicy: ClusterFirst
restartPolicy: Always
securityContext: {}
terminationGracePeriodSeconds:
imagePullPolicy: Always
imagePullSecrets:
- {name: ccr.ccs.tencentyun.com.key} status:
availableReplicas:
conditions:
- lastTransitionTime: --15T09::17Z
lastUpdateTime: --15T09::17Z
message: ReplicaSet "gateway-6bf6db5c4f" has successfully progressed.
reason: NewReplicaSetAvailable
status: "True"
type: Progressing
- lastTransitionTime: --15T09::59Z
lastUpdateTime: --15T09::59Z
message: Deployment has minimum availability.
reason: MinimumReplicasAvailable
status: "True"
type: Available
observedGeneration:
readyReplicas:
replicas:
updatedReplicas:

service.yaml

kind: Service
apiVersion: v1
metadata:
name: gateway
namespace: rubikt
selfLink: /api/v1/namespaces/rubikt/services/gateway
uid: 43fd6588-4a14-11e9-80d3-0050569b47c5
resourceVersion: ''
labels: {app: gateway}
spec:
ports:
- {protocol: TCP, port: , targetPort: , nodePort: }
selector: {app: gateway}
type: NodePort
sessionAffinity: None
status:
loadBalancer: {}

Chart.yaml

name: gateway
version: "v1.0"
description: gateway

values.yaml

docker:
registry: 192.168.2.50/health/gateway:1.5.-SNAPSHOT
pullPolicy: Always
core:
replicas:
config:
version: "v1.0"

10. 使用命令来验证chart配置有效性

该输出中含模板的变量配置和最终渲染的yaml文件

(当使用kubernetes部署应用时,实际上是将templates渲染成最终的kubernetes能够识别的yaml格式)

$ helm install --dry-run --debug gateway
[debug] Created tunnel using local port: '' [debug] SERVER: "127.0.0.1:56560" [debug] Original chart version: ""
[debug] CHART PATH: D:\zhuojian-projects\rubik-T\k8s\gateway NAME: snug-hare
REVISION:
RELEASED: Thu Jul ::
CHART: gateway-v1.
USER-SUPPLIED VALUES:
{} COMPUTED VALUES:
config:
version: v1.
core:
replicas:
docker:
pullPolicy: Always
registry: 192.168.2.50/health/gateway:1.5.-SNAPSHOT HOOKS:
MANIFEST: ---
# Source: gateway/templates/service.yaml
kind: Service
apiVersion: v1
metadata:
name: gateway
namespace: rubikt
selfLink: /api/v1/namespaces/rubikt/services/gateway
uid: 43fd6588-4a14-11e9-80d3-0050569b47c5
resourceVersion: ''
labels: {app: gateway}
spec:
ports:
- {protocol: TCP, port: , targetPort: , nodePort: }
selector: {app: gateway}
type: NodePort
sessionAffinity: None
status:
loadBalancer: {}
---
# Source: gateway/templates/deployment.yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
annotations:
deployment.kubernetes.io/revision: ""
creationTimestamp: --15T09::17Z
generation:
labels:
app: gateway
name: gateway
namespace: rubikt
resourceVersion: ""
selfLink: /apis/extensions/v1beta1/namespaces/rubikt/deployments/gateway
uid: a0ca862b-4a12-11e9-80d3-0050569b47c5
spec:
progressDeadlineSeconds:
replicas:
revisionHistoryLimit:
selector:
matchLabels:
app: gateway
strategy:
rollingUpdate:
maxSurge: %
maxUnavailable: %
type: RollingUpdate
template:
metadata:
creationTimestamp: null
labels:
app: gateway
spec:
containers:
- image: 192.168.2.50/health/gateway:1.5.-SNAPSHOT
ports:
- {containerPort: , protocol: TCP}
env:
- {name: JAVA_OPTS, value: '-Denv=dev -Ddev_meta=http://apollo.dev.zwjk.com -Dapp.id=health-gateway -server -Xmx768m'}
- {name: CONSUL_URL, value: 10.109.36.166}
- {name: CONSUL_HOST, value: 10.100.39.12}
- {name: CONSUL_PORT, value: ''}
terminationMessagePath: /dev/termination-log
name: gateway
resources:
limits:
cpu: 200m
memory: 768Mi
requests:
cpu: 50m
memory: 512Mi
dnsPolicy: ClusterFirst
restartPolicy: Always
securityContext: {}
terminationGracePeriodSeconds:
imagePullPolicy: Always
imagePullSecrets:
- {name: ccr.ccs.tencentyun.com.key} status:
availableReplicas:
conditions:
- lastTransitionTime: --15T09::17Z
lastUpdateTime: --15T09::17Z
message: ReplicaSet "gateway-6bf6db5c4f" has successfully progressed.
reason: NewReplicaSetAvailable
status: "True"
type: Progressing
- lastTransitionTime: --15T09::59Z
lastUpdateTime: --15T09::59Z
message: Deployment has minimum availability.
reason: MinimumReplicasAvailable
status: "True"
type: Available
observedGeneration:
readyReplicas:
replicas:
updatedReplicas:

11. 安装Chart到kubernetes

helm install -n gateway gateway

现在gateway已经部署到集群上了,本地可执行命令查看实例

$ kubectl get pods --namespace rubikt
NAME READY STATUS RESTARTS AGE
gateway-86584799f-kvvsh / Running 31h

12. 查看部署的release

$ helm list
NAME REVISION UPDATED STATUS CHART APP VERSION NAMESPACE
gateway Thu Jul :: DEPLOYED gateway-v1. default

当前release包含的资源有:Service、Deployment、Secret、PersistentVolumeClaim

查看Service:

$ kubectl get service --namespace rubikt
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
gateway NodePort 10.109.149.47 <none> :/TCP 25h

查看Deployment:

$ kubectl get Deployment --namespace rubikt
NAME READY UP-TO-DATE AVAILABLE AGE
gateway / 47h

查看Secret:

$ kubectl get Secret --namespace rubikt
NAME TYPE DATA AGE
default-token-687fw kubernetes.io/service-account-token 2d5h

查看PersistentVolumeClaim:

$ kubectl get PersistentVolumeClaim --namespace rubikt
No resources found.

 13. 配置升级

更新了配置文件之后,可以使用upgrade命令进行更新(以此做到应用升级)

$ helm upgrade config config --description config升级 --version 2.0
Release "config" has been upgraded.
LAST DEPLOYED: Tue Jul ::
NAMESPACE: default
STATUS: DEPLOYED RESOURCES:
==> v1/Pod(related)
NAME READY STATUS RESTARTS AGE
config-6c7b9f6885-jkf6j / Running 3m55s
config-fcf75984-vrd2f / ContainerCreating 0s ==> v1beta1/Deployment
NAME READY UP-TO-DATE AVAILABLE AGE
config / 23m

可以看到部署的config已经升级了一个版本,revision = 2

$ helm list
NAME REVISION UPDATED STATUS CHART APP VERSION NAMESPACE
config Tue Jul :: DEPLOYED config-v1. default

14. 版本回退

回退应用版本,先使用helm history命令查看变更记录

$ helm history config
REVISION UPDATED STATUS CHART DESCRIPTION
Tue Jul :: SUPERSEDED config-v1. Install complete
Tue Jul :: SUPERSEDED config-v1. Upgrade complete
Tue Jul :: SUPERSEDED config-v1. Rollback to
Tue Jul :: DEPLOYED config-v1. config升级

回滚到reversion为2的版本

$ helm rollback config
Rollback was a success.

另外: 部署到k8s上之后,可能会出现的问题:(表明需要配置内存空间大小)

 

使用helm进行kubernetes包管理的更多相关文章

  1. Helm - Kubernetes包管理专家

    What is Helm? - The package manager for kubernetes, Helm is the best way to find, share, and use sof ...

  2. kubernetes包管理工具Helm安装

    helm官方建议使用tls,首先生成证书. openssl genrsa -out ca.key.pem openssl req -key ca.key.pem -new -x509 -days -s ...

  3. Kubernetes-17:Kubernets包管理工具—>Helm介绍与使用

    Kubernets包管理工具->Helm 什么是Helm? 我们都知道,Linux系统各发行版都有自己的包管理工具,比如Centos的YUM,再如Ubuntu的APT. Kubernetes也有 ...

  4. Helm包管理

    Helm Kubernetes 包管理工具 Helm 可以帮助我们管理 Kubernetes 应用程序 - Helm Charts 可以定义.安装和升级复杂的 Kubernetes 应用程序,Char ...

  5. 第十一章 Helm-kubernetes的包管理器(上)

    Helm - K8s的包管理器 11.1 Why Helm K8s能够很好的组织和编排容器,但它缺少一个更高层次的应用打包工具,Helm就是干这个的. 比如对于一个MySQL服务,K8s需要部署如下对 ...

  6. 使用 Helm 包管理工具简化 Kubernetes 应用部署

    当在 Kubernetes 中已经部署很多应用时,后续需要对每个应用的 yaml 文件进行维护操作,这个过程会变的很繁琐,我们可以使用 Helm 来简化这些工作.Helm 是 Kubernetes 的 ...

  7. Kubernetes学习之路(二十五)之Helm程序包管理器

    目录 1.Helm的概念和架构 2.部署Helm (1)下载helm (2)部署Tiller 3.helm的使用 4.chart 目录结构 5.chart模板 6.定制安装MySQL chart (1 ...

  8. Helm:kubernetes应用包管理工具

    概要 Helm:kubernetes应用包管理工具 K8s部署应用的时候,应用会通过yaml描述信息调用K8s-api:Helm即是管理这些Yaml的应用包管理工具 组成 Helm包含5个部分 Hel ...

  9. 云原生之旅 - 5)Kubernetes时代的包管理工具 Helm

    前言 上一篇文章 [基础设施即代码 使用 Terraform 创建 Kubernetes] 教会了你如何在Cloud上面建Kubernetes资源,那么本篇来讲一下如何在Kubernetes上面部署应 ...

随机推荐

  1. asp.net core MVC 过滤器之ExceptionFilter过滤器(一)

    简介 异常过滤器,顾名思义,就是当程序发生异常时所使用的过滤器.用于在系统出现未捕获异常时的处理. 实现一个自定义异常过滤器 自定义一个异常过滤器需要实现IExceptionFilter接口 publ ...

  2. linuxmint安装Tools找不到Tools的压缩包问题

    安装Linuxmint之后按照惯例安装Tools,打开桌面上的Tools光盘之后找不到压缩包. PS:因为已经装好了,就不上图了,按照下面的步骤做就没有问题了. 1:找到vmware的安装目录下的li ...

  3. 查看mysql字符集、修改数据库、数据表、字段字符集

    查看所有表的字符集 SELECT table_name, table_type, engine, version, table_collation FROM information_schema.ta ...

  4. git 从远程克隆代码并实现分支开发,合并分支,上传本地代码到远程

    首先确认你已经安装了git 1.克隆远程代码到本地的操作 git clone 地址   打开git操作命令行 鼠标右键点击        复制需要克隆的项目的地址类似下面的ssh     输入命令进行 ...

  5. JavaScript 流程控制(二)循环结构

    一.while 语句 语法结构: 声明循环变量:while (循环条件) { //循环体 // 迭代条件 } 当循环条件为 true 时,执行循环体:当循环条件为false时,结束循环. 二.do.. ...

  6. HTML5 表单新增内容

    一.H5 新增控件 1.datalist 元素 datalist 标签定义选项列表,请与 input 元素配合使用该元素.可为输入框提供一个可选的列表,可以直接选择列表项,也可以不选择列表中的项,自行 ...

  7. Python学习的开端

    C语言太麻烦了,所以我打算自学Python. 自学选的书是<父与子的编程之旅>,这本书还是比较通俗易懂的. 贴上书上教我编写的猜数字游戏代码 import random secret = ...

  8. 连接mysql报"ERROR 1130: Host xxx.xxx.xxx.xxx is not allowed to connect to this MySQL server"

    最近在服务器上部署好的应用突然间连接不上mysql数据库,报错“ERROR 1130: Host xxx.xxx.xxx.xxx is not allowed to connect to this M ...

  9. 深入理解Java类加载器(一):Java类加载原理解析

    摘要: 每个开发人员对java.lang.ClassNotFoundExcetpion这个异常肯定都不陌生,这个异常背后涉及到的是Java技术体系中的类加载机制.本文简述了JVM三种预定义类加载器,即 ...

  10. watch - 实时查看命令执行结果

    watch - execute a program periodically, showing output fullscreen 定期执行一个程序,全屏显示输出 watch重复运行命令,显示其输出和 ...