关于java:Helm-带你飞

42次阅读

共计 4383 个字符,预计需要花费 11 分钟才能阅读完成。

文章目录

[toc]

在没应用 Helm之前,向 K8S部署利用,咱们要顺次部署 deploymentsvc 等,步骤较繁琐。况且随着很多我的项目微服务化,简单的利用在容器中部署以及治理显得较为简单,Helm通过打包的形式,反对公布的版本治理和管制,很大水平上简化了 K8S利用的部署和治理

一、Helm 简介

Helm实质就是让 K8S的利用治理(DeploymentService等 ) 可配置,能动静生成。通过动静生成 K8S资源清单文件(deployment.yamlservice.yaml)。而后调用 Kubectl主动执行 K8S资源部署。

Helm是官网提供的相似于 YUM的包管理器,是部署环境的流程封装。Helm有两个重要的概念:chartrelease

  • chart是创立一个利用的信息汇合,包含各种 Kubernetes对象的配置模板、参数定义、依赖关系、文档阐明等。chart是利用部署的自蕴含逻辑单元。能够将 chart设想成 aptyum中的软件安装包
  • releasechart的运行实例,代表了一个正在运行的利用。当 chart被装置到 Kubernetes集群,就生成一个 releasechart可能屡次装置到同一个集群,每次装置都是一个 release

Helm蕴含两个组件:Helm客户端和 Tiller服务器,如下图所示:

Helm客户端负责 chartrelease的创立和治理以及和 Tiller的交互。Tiller服务器运行在 K8S集群中,它会解决 Helm客户端的申请,与 Kubernetes API Server交互

二、Helm 部署

下载 helm客户端:

[root@master helm]

[root@master helm]

因为 api server开启了 RBAC访问控制,所以须要创立 tiller应用的 service account,并调配适合的角色给它,这样能力拜访 api server,具体内容能够查看 helm文档中的 Role-based Access Control。这里简略起见间接调配 cluster- admin这个集群内置的 ClusterRole给它,创立 rbac-config.yaml文件:

[root@master helm]
apiVersion: v1
kind: ServiceAccount
metadata:
  name: tiller
  namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
  name: tiller
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: cluster-admin
subjects:
  - kind: ServiceAccount
    name: tiller
    namespace: kube-system

[root@master helm]

[root@worker1 ~]

[root@master helm]

[root@master helm]
tiller-deploy-6d47785b7c-jbdv7   1/1     Running   0          1h

[root@master helm]
Client: &version.Version{SemVer:"v2.13.1", GitCommit:"618447cbf203d147601b4b9bd7f8c37a5d39fbb4", GitTreeState:"clean"}
Server: &version.Version{SemVer:"v2.13.1", GitCommit:"618447cbf203d147601b4b9bd7f8c37a5d39fbb4", GitTreeState:"clean"}

三、Helm 自定义模板

[root@master helm]

[root@master hello-world]
name: hello-world
version: 1.0.0

[root@master templates]

[root@master templates]
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: hello-world
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: hello-world
    spec:
      containers:
        - name: hello-world
          image: hub.hc.com/library/myapp:v1
          ports:
            - containerPort: 80
              protocol: TCP

[root@master templates]
apiVersion: v1
kind: Service
metadata:
  name: hello-world
spec:
  type: NodePort
  ports:
  - port: 80
    targetPort: 80
    protocol: TCP
  selector:
    app: hello-world

[root@master hello-world]

[root@master hello-world]
NAME             REVISION    UPDATED                     STATUS      CHART                APP VERSION    NAMESPACE
dunking-manta    2           Tue Aug 18 10:04:27 2020    DEPLOYED    hello-world-1.0.0                   default

[root@master templates]

[root@master templates]

[root@master templates]
NAME             REVISION    UPDATED                     STATUS     CHART                APP VERSION    NAMESPACE
dunking-manta    2           Tue Aug 18 10:04:27 2020    DELETED    hello-world-1.0.0                   default

[root@master templates]
REVISION    UPDATED                     STATUS        CHART             DESCRIPTION
1           Tue Aug 18 09:49:45 2020    SUPERSEDED    hello-world-1.0.0 Install complete
2           Tue Aug 18 10:04:27 2020    SUPERSEDED    hello-world-1.0.0 Deletion complete

[root@master templates]

[root@master templates]

动静切换版本:

[root@master hello-world]
image:
  repository: wangyanglinux/myapp
  tag: 'v2'

[root@master ~]
Hello MyApp | Version: v1 | <a href="hostname.html">Pod Name</a>

[root@master hello-world]

[root@master ~]
Hello MyApp | Version: v2 | <a href="hostname.html">Pod Name</a>

[root@master ~]

[root@master ~]
Hello MyApp | Version: v1 | <a href="hostname.html">Pod Name</a>

Debug


[root@master ~]

四、应用 Helm 部署 dashboard


[root@worker1 ~]
fbdfe08b001c: Loading layer  122.3MB/122.3MB
Loaded image: k8s.gcr.io/kubernetes-dashboard-amd64:v1.10.1

[root@master Dashboard]
[root@master Dashboard]
[root@master Dashboard]
[root@master Dashboard]
NAME      URL
local     http://127.0.0.1:8879/charts
stable    https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts

[root@master Dashboard]
[root@master Dashboard]
[root@master kubernetes-dashboard]
image:
  repository: k8s.gcr.io/kubernetes-dashboard-amd64
  tag: v1.10.1
ingress:
  enabled: true
  hosts:
    - k8s.frognew.com
  annotations:
    nginx.ingress.kubernetes.io/ssl-redirect: "true"
    nginx.ingress.kubernetes.io/backend-protocol: "HTTPS"
  tls:
    - secretName: frognew-com-tls-secret
      hosts:
      - k8s.frognew.com
rbac:
  clusterAdminRole: true

[root@master kubernetes-dashboard]
> -n kubernetes-dashboard \
> --namespace kube-system  \
> -f k8s-dashboard.yaml

[root@master kubernetes-dashboard]
NAME                   TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)                  AGE
kubernetes-dashboard   ClusterIP   10.105.124.175   <none>        443/TCP                  3m39s

[root@master kubernetes-dashboard]

[root@master kubernetes-dashboard]
NAME                   TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)                  AGE
kubernetes-dashboard   NodePort    10.105.124.175   <none>        443:30186/TCP            9m5s

五、应用 dashboard 部署利用

应用火狐浏览器拜访 https://192.168.182.100:30186,抉择令牌并输出下方查到的 token

查问 dashboard-token

[root@master kubernetes-dashboard]
kubernetes-dashboard-token-5lgp8                 kubernetes.io/service-account-token   3      27m

[root@master kubernetes-dashboard]

进入到 dashboard面板后,点击创立利用:

创立利用的参数如下,点击部署

容器部署胜利:

微信搜一搜 : 全栈小刘,获取文章 pdf 版本

正文完
 0