文章目錄
目錄- 文章目錄
在沒使用
Helm之前,向K8S部署應用,我們要依次部署deployment、svc等,步驟較繁瑣,況且隨著很多專案微服務化,復雜的應用在容器中部署以及管理顯得較為復雜,Helm通過打包的方式,支持發布的版本管理和控制,很大程度上簡化了K8S應用的部署和管理
一、Helm 簡介
Helm本質就是讓 K8S的應用管理( Deployment、 Service等 ) 可配置,能動態生成,通過動態生成 K8S資源清單檔案( deployment.yaml, service.yaml),然后呼叫 Kubectl自動執行 K8S資源部署,
Helm是官方提供的類似于 YUM的包管理器,是部署環境的流程封裝, Helm有兩個重要的概念: chart和 release:
chart是創建一個應用的資訊集合,包括各種Kubernetes物件的配置模板、引數定義、依賴關系、檔案說明等,chart是應用部署的自包含邏輯單元,可以將chart想象成apt、yum中的軟體安裝包release是chart的運行實體,代表了一個正在運行的應用,當chart被安裝到Kubernetes集群,就生成一個release,chart能夠多次安裝到同一個集群,每次安裝都是一個release,
Helm包含兩個組件: Helm客戶端和 Tiller服務器,如下圖所示:
Helm客戶端負責 chart和 release的創建和管理以及和 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="https://www.cnblogs.com/spiritmark/p/hostname.html">Pod Name</a>
[root@master hello-world]
[root@master ~]
Hello MyApp | Version: v2 | <a href="https://www.cnblogs.com/spiritmark/p/hostname.html">Pod Name</a>
[root@master ~]
[root@master ~]
Hello MyApp | Version: v1 | <a href="https://www.cnblogs.com/spiritmark/p/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 版本
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/187012.html
標籤:Java
