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. xshell连接本地linux虚拟机速度很慢的解决办法

    今天发现用xshell连接centos太慢,网上查询后发现是因为ssh的服务端在连接时会自动检测dns环境是否一致导致的,修改为不检测即可. 修改文件位置:vi /etc/ssh/sshd_confi ...

  2. 【JVM学习笔记二】垃圾收集器与内存分配策略

    1. 概述 1) GC的历史比Java久远 2) GC需要完成的三件事: | 哪些内存需要回收 | 什么时候回收 | 如何回收 3) Java内存运行时区域各个部分: | Java虚拟机栈.计数器.本 ...

  3. js设置全局变量与读取全局变量

    方法1: 设置: var a = 1; 读取: a window.a window['a'] 方法2: 设置: window.b=2; 读取: b window.b window['b'] 方法3: ...

  4. 如何使用Python的Django框架创建自己的网站

    如何使用Python的Django框架创建自己的网站 Django建站主要分四步:1.创建Django项目,2.将网页模板移植到Django项目中,3.数据交互,4.数据库 1创建Django项目 本 ...

  5. RabbitMQ启动出现的问题与解决办法

    问题1 使用命令启动 service rabbitmq-server start 报错如下: Starting rabbitmq-server (via systemctl): Job for rab ...

  6. 面试题:栈的push和pop序列是否一致

    参数是两个数组,arr1,arr2 stack stack = new Stack() for(int i=0;j=0;i<arr1.length;i++){ stack.push(arr[i] ...

  7. mysql 查询当天数据

    查询当天数据 select * from tab where FROM_UNIXTIME(fabutime, '%Y%m%d') = 20121217;   mysql TO_DAYS(date) 函 ...

  8. Windows Server 2012 R2 远程桌面自动设置为不允许连接问题解决方案

    用“gpedit.msc”调出策略组设置窗口,在策略组界面点击:计算机配置->管理模块->Windows组件->远程桌面服务->远程桌面会话主机->连接->允许用户 ...

  9. Httpd服务入门知识-Httpd服务常见配置案例之基于用户账号实现访问控制

    Httpd服务入门知识-Httpd服务常见配置案例之基于用户账号实现访问控制 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.基于用户的访问控制概述 认证质询: WWW-Auth ...

  10. PAT甲级1015题解——令人迷茫的翻译

    题目分析: 本题计算过程简单,但翻译令我迷茫:题意读清楚很重要(反正我是懵逼了)对于一个10进制的数,如果它是一个素数,把它转换成d进制,再将这个序列逆序排,这个逆序的d进制数的10进制表示如果也是素 ...