Helm的部署

Helm可以幫助kubernetes進(jìn)行打包的管理羹膳,是重要的工具之一睡互,因?yàn)榍懊姘惭b的kubernetes是1.18版本,在部署Helm的時(shí)候遇到了一些問題,特此記錄一下

首先查一下kubernetes的版本

[root@k8s-master k8s]# kubectl version 
Client Version: version.Info{Major:"1", Minor:"18", GitVersion:"v1.18.1", GitCommit:"7879fc12a63337efff607952a323df90cdc7a335", GitTreeState:"clean", BuildDate:"2020-04-08T17:38:50Z", GoVersion:"go1.13.9", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"18", GitVersion:"v1.18.1", GitCommit:"7879fc12a63337efff607952a323df90cdc7a335", GitTreeState:"clean", BuildDate:"2020-04-08T17:30:47Z", GoVersion:"go1.13.9", Compiler:"gc", Platform:"linux/amd64"}

安裝Helm

wget https://storage.googleapis.com/kubernetes-helm/helm-v2.12.1-linux-amd64.tar.gz
tar -zxvf helm-v2.12.1-linux-amd64.tar.gz
cd linux-amd64/
# 拷貝helm到 /usr/local/bin 
cp helm /usr/local/bin

驗(yàn)證Helm

helm version
Client: &version.Version{SemVer:"v2.12.1", GitCommit:"02a47c7249b1fc6d8fd3b94e6b4babf9d818144e", GitTreeState:"clean"}
Error: cannot connect to Tiller

出現(xiàn)問題就珠,鏈接不到Tiller寇壳,這時(shí)Tiller還沒有安裝,是正常的現(xiàn)象
安裝Tiller
參考其他文檔或博客妻怎,安裝Tiller壳炎,so easy,只需要執(zhí)行helm init就可以了逼侦。當(dāng)執(zhí)行以下命令時(shí)匿辩,出現(xiàn)了錯(cuò)誤

$ helm init --service-account tiller
$HELM_HOME has been configured at /Users/xxxx/.helm.
Error: error installing: the server could not find the requested resource

各種查詢Google下,找到了原因榛丢,helm 2.xx版本對(duì)于kubernetes 1.16以上的支持有些問題铲球,主要是1.16以后yaml文件的格式發(fā)生了變化,在查到的討論中提到以下命令可以安裝晰赞。(查到的文獻(xiàn)鏈接:Helm init fails on Kubernetes 1.16.0 #6374

helm init --service-account tiller --output yaml | sed 's@apiVersion: extensions/v1beta1@apiVersion: apps/v1@' | sed 's@  replicas: 1@  replicas: 1\n  selector: {"matchLabels": {"app": "helm", "name": "tiller"}}@' | kubectl apply -f -

執(zhí)行以上命令稼病,發(fā)現(xiàn)確實(shí)提示tiller-deploy已經(jīng)安裝,這時(shí)去查看deployments發(fā)現(xiàn)

[root@k8s-master k8s]# kubectl get deployments --all-namespaces 
NAMESPACE     NAME                      READY   UP-TO-DATE   AVAILABLE   AGE
kube-system   calico-kube-controllers   1/1     1            1           3d4h
kube-system   coredns                   2/2     2            2           3d4h
kube-system   tiller-deploy             0/1     0            0           17m

雖然安裝上了掖鱼,但始終不能ready然走,為什么呢?繼續(xù)查看pods锨用,根本就沒有till-deploy-xxx的pod生成

[root@k8s-master k8s]# kubectl get pods --all-namespaces 
NAMESPACE     NAME                                       READY   STATUS    RESTARTS   AGE
default       mypod                                      1/1     Running   0          143m
default       node-exporter-daemonset-s4j7s              1/1     Running   1          15h
default       node-exporter-daemonset-swhbz              1/1     Running   1          15h
kube-system   calico-kube-controllers-57546b46d6-nt89k   1/1     Running   6          3d4h
kube-system   calico-node-24mxg                          1/1     Running   4          41h
kube-system   calico-node-ldgcf                          1/1     Running   5          2d14h
kube-system   calico-node-lxwl7                          1/1     Running   6          3d4h
kube-system   coredns-7ff77c879f-5xxgt                   1/1     Running   6          3d4h
kube-system   coredns-7ff77c879f-m6g58                   1/1     Running   6          3d4h
kube-system   etcd-k8s-master                            1/1     Running   6          3d4h
kube-system   kube-apiserver-k8s-master                  1/1     Running   11         3d4h
kube-system   kube-controller-manager-k8s-master         1/1     Running   7          3d4h
kube-system   kube-proxy-lv6p4                           1/1     Running   5          2d14h
kube-system   kube-proxy-t4vtw                           1/1     Running   6          3d4h
kube-system   kube-proxy-xlzvk                           1/1     Running   4          41h
kube-system   kube-scheduler-k8s-master                  1/1     Running   7          3d4h

中間嘗試了各種查找,沒有頭緒隘谣≡鲇担回過頭來(lái),把上面的sed命令產(chǎn)生的yaml文件輸出

helm init --service-account tiller --output yaml | sed 's@apiVersion: extensions/v1beta1@apiVersion: apps/v1@' | sed 's@  replicas: 1@  replicas: 1\n  selector: {"matchLabels": {"app": "helm", "name": "tiller"}}@' > tiller.yaml

查看這個(gè)yaml文件寻歧,發(fā)現(xiàn)image用的是image: gcr.io/kubernetes-helm/tiller:v2.12.1掌栅,覺得可能和這個(gè)相關(guān),是不是沒能下載到image码泛,換成以下阿里云的鏡像猾封。 結(jié)果還是一樣,其實(shí)這時(shí)pod還沒有生成噪珊,還沒有到下載鏡像的步驟晌缘。

---
apiVersion: apps/v1
kind: Deployment
metadata:
  creationTimestamp: null
  labels:
    app: helm
    name: tiller
  name: tiller-deploy
  namespace: kube-system
spec:
  replicas: 1
  selector: {"matchLabels": {"app": "helm", "name": "tiller"}}
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: helm
        name: tiller
    spec:
      automountServiceAccountToken: true
      containers:
      - env:
        - name: TILLER_NAMESPACE
          value: kube-system
        - name: TILLER_HISTORY_MAX
          value: "0"
        image: registry.cn-hangzhou.aliyuncs.com/google_containers/tiller:v2.12.1
        imagePullPolicy: IfNotPresent
        livenessProbe:
          httpGet:
            path: /liveness
            port: 44135
          initialDelaySeconds: 1
          timeoutSeconds: 1
        name: tiller
        ports:
        - containerPort: 44134
          name: tiller
        - containerPort: 44135
          name: http
        readinessProbe:
          httpGet:
            path: /readiness
            port: 44135
          initialDelaySeconds: 1
          timeoutSeconds: 1
        resources: {}
      serviceAccountName: tiller
status: {}

---
apiVersion: v1
kind: Service
metadata:
  creationTimestamp: null
  labels:
    app: helm
    name: tiller
  name: tiller-deploy
  namespace: kube-system
spec:
  ports:
  - name: tiller
    port: 44134
    targetPort: tiller
  selector:
    app: helm
    name: tiller
  type: ClusterIP
status:
  loadBalancer: {}                                                                                                                                                                                                                     

思考一下kubernetes的構(gòu)架,下載deployment已經(jīng)生成痢站,但pod還沒有生成磷箕,這個(gè)應(yīng)該是deployment control manager的職責(zé)范圍,在對(duì)應(yīng)的日志中是否能夠看到端倪呢阵难? 先去看看

[root@k8s-master k8s]# kubectl logs kube-controller-manager-k8s-master --namespace=kube-system

I0718 17:21:59.039703       1 event.go:278] Event(v1.ObjectReference{Kind:"ReplicaSet", Namespace:"kube-system", Name:"tiller-deploy-7566c65bf6", UID:"8f94a829-cc7d-4f87-80fa-329c0e3fde58", APIVersion:"apps/v1", ResourceVersion:"230088", FieldPath:""}): type: 'Warning' reason: 'FailedCreate' Error creating: pods "tiller-deploy-7566c65bf6-" is forbidden: error looking up service account kube-system/tiller: serviceaccount "tiller" not found
E0718 17:22:40.031087       1 replica_set.go:535] sync "kube-system/tiller-deploy-7566c65bf6" failed with pods "tiller-deploy-7566c65bf6-" is forbidden: error looking up service account kube-system/tiller: serviceaccount "tiller" not found
I0718 17:22:40.031520       1 event.go:278] Event(v1.ObjectReference{Kind:"ReplicaSet", Namespace:"kube-system", Name:"tiller-deploy-7566c65bf6", UID:"8f94a829-cc7d-4f87-80fa-329c0e3fde58", APIVersion:"apps/v1", ResourceVersion:"230088", FieldPath:""}): type: 'Warning' reason: 'FailedCreate' Error creating: pods "tiller-deploy-7566c65bf6-" is forbidden: error looking up service account kube-system/tiller: serviceaccount "tiller" not found
E0718 17:24:01.982900       1 replica_set.go:535] sync "kube-system/tiller-deploy-7566c65bf6" failed with pods "tiller-deploy-7566c65bf6-" is forbidden: error looking up service account kube-system/tiller: serviceaccount "tiller" not found
I0718 17:24:01.983226       1 event.go:278] Event(v1.ObjectReference{Kind:"ReplicaSet", Namespace:"kube-system", Name:"tiller-deploy-7566c65bf6", UID:"8f94a829-cc7d-4f87-80fa-329c0e3fde58", APIVersion:"apps/v1", ResourceVersion:"230088", FieldPath:""}): type: 'Warning' reason: 'FailedCreate' Error creating: pods "tiller-deploy-7566c65bf6-" is forbidden: error looking up service account kube-system/tiller: serviceaccount "tiller" not found
E0718 17:26:45.835530       1 replica_set.go:535] sync "kube-system/tiller-deploy-7566c65bf6" failed with pods "tiller-deploy-7566c65bf6-" is forbidden: error looking up service account kube-system/tiller: serviceaccount "tiller" not found

輸出很多岳枷,只拿到后面幾行,可以看到tiller-deploy-7566c65bf6- pod創(chuàng)建失敗的原因是serviceaccount "tiller" not found】辗保可以通過kubectl get serviceaccount --all-namespaces去查看殿衰,系統(tǒng)里面有很多serviceaccount,也確實(shí)沒有tiller盛泡。

拿著”tiller service account yaml“闷祥,去Google一下,發(fā)現(xiàn)了創(chuàng)建serviceaccount的yaml饭于, Example: Service account with cluster-admin role蜀踏,在本地使用示例創(chuàng)建yaml文件并apply。

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 
[root@k8s-master k8s]# kubectl apply -f rbac-config.yaml 
serviceaccount/tiller created
clusterrolebinding.rbac.authorization.k8s.io/tiller created

可以看到這個(gè)serviceaccount已經(jīng)創(chuàng)建了掰吕,可以再通過kubectl get serviceaccount --all-namespaces查詢一下果覆,可以看到已經(jīng)有了。(只顯示了部分)

[root@k8s-master k8s]# kubectl get serviceAccount --all-namespaces 
NAMESPACE         NAME                                 SECRETS   AGE
default           default                              1         3d4h
kube-system       statefulset-controller               1         3d4h
kube-system       tiller                               1         57s
kube-system       token-cleaner                        1         3d4h
kube-system       ttl-controller                       1         3d4h

這時(shí)再去查看居然還沒有產(chǎn)生pod殖熟。日志和上面一樣局待,還在說(shuō)serviceaccount不存在的問題。將deployment刪除再重新安裝

[root@k8s-master k8s]# kubectl delete -f newTiller.ali.yaml 

[root@k8s-master k8s]# kubectl apply -f newTiller.ali.yaml 
deployment.apps/tiller-deploy created
service/tiller-deploy created
#查詢
[root@k8s-master k8s]# kubectl get pods --all-namespaces 
NAMESPACE     NAME                                       READY   STATUS    RESTARTS   AGE
default       mypod                                      1/1     Running   0          162m
default       node-exporter-daemonset-s4j7s              1/1     Running   1          15h
default       node-exporter-daemonset-swhbz              1/1     Running   1          15h
kube-system   calico-kube-controllers-57546b46d6-nt89k   1/1     Running   6          3d4h
kube-system   calico-node-24mxg                          1/1     Running   4          41h
kube-system   calico-node-ldgcf                          1/1     Running   5          2d15h
kube-system   calico-node-lxwl7                          1/1     Running   6          3d4h
kube-system   coredns-7ff77c879f-5xxgt                   1/1     Running   6          3d4h
kube-system   coredns-7ff77c879f-m6g58                   1/1     Running   6          3d4h
kube-system   etcd-k8s-master                            1/1     Running   6          3d4h
kube-system   kube-apiserver-k8s-master                  1/1     Running   11         3d4h
kube-system   kube-controller-manager-k8s-master         1/1     Running   7          3d4h
kube-system   kube-proxy-lv6p4                           1/1     Running   5          2d15h
kube-system   kube-proxy-t4vtw                           1/1     Running   6          3d4h
kube-system   kube-proxy-xlzvk                           1/1     Running   4          41h
kube-system   kube-scheduler-k8s-master                  1/1     Running   7          3d4h
kube-system   tiller-deploy-7566c65bf6-6l9dx             1/1     Running   0          23s

終于pod啟動(dòng)起來(lái)了菱属,而且進(jìn)入的ready的狀態(tài)钳榨。

[root@k8s-master k8s]# helm version
Client: &version.Version{SemVer:"v2.12.1", GitCommit:"02a47c7249b1fc6d8fd3b94e6b4babf9d818144e", GitTreeState:"clean"}
Server: &version.Version{SemVer:"v2.12.1", GitCommit:"02a47c7249b1fc6d8fd3b94e6b4babf9d818144e", GitTreeState:"clean"}

至此,可以進(jìn)行后面的實(shí)驗(yàn)了纽门。

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末薛耻,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子赏陵,更是在濱河造成了極大的恐慌饼齿,老刑警劉巖,帶你破解...
    沈念sama閱讀 211,265評(píng)論 6 490
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件蝙搔,死亡現(xiàn)場(chǎng)離奇詭異缕溉,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)吃型,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,078評(píng)論 2 385
  • 文/潘曉璐 我一進(jìn)店門证鸥,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái),“玉大人勤晚,你說(shuō)我怎么就攤上這事枉层。” “怎么了赐写?”我有些...
    開封第一講書人閱讀 156,852評(píng)論 0 347
  • 文/不壞的土叔 我叫張陵返干,是天一觀的道長(zhǎng)。 經(jīng)常有香客問我血淌,道長(zhǎng)矩欠,這世上最難降的妖魔是什么财剖? 我笑而不...
    開封第一講書人閱讀 56,408評(píng)論 1 283
  • 正文 為了忘掉前任,我火速辦了婚禮癌淮,結(jié)果婚禮上躺坟,老公的妹妹穿的比我還像新娘。我一直安慰自己乳蓄,他們只是感情好咪橙,可當(dāng)我...
    茶點(diǎn)故事閱讀 65,445評(píng)論 5 384
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著虚倒,像睡著了一般美侦。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上魂奥,一...
    開封第一講書人閱讀 49,772評(píng)論 1 290
  • 那天菠剩,我揣著相機(jī)與錄音,去河邊找鬼耻煤。 笑死具壮,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的哈蝇。 我是一名探鬼主播棺妓,決...
    沈念sama閱讀 38,921評(píng)論 3 406
  • 文/蒼蘭香墨 我猛地睜開眼,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼炮赦!你這毒婦竟也來(lái)了怜跑?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 37,688評(píng)論 0 266
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤吠勘,失蹤者是張志新(化名)和其女友劉穎性芬,沒想到半個(gè)月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體看幼,經(jīng)...
    沈念sama閱讀 44,130評(píng)論 1 303
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡批旺,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,467評(píng)論 2 325
  • 正文 我和宋清朗相戀三年幌陕,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了诵姜。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 38,617評(píng)論 1 340
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡搏熄,死狀恐怖棚唆,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情心例,我是刑警寧澤宵凌,帶...
    沈念sama閱讀 34,276評(píng)論 4 329
  • 正文 年R本政府宣布,位于F島的核電站止后,受9級(jí)特大地震影響瞎惫,放射性物質(zhì)發(fā)生泄漏溜腐。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,882評(píng)論 3 312
  • 文/蒙蒙 一瓜喇、第九天 我趴在偏房一處隱蔽的房頂上張望挺益。 院中可真熱鬧,春花似錦乘寒、人聲如沸望众。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,740評(píng)論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)烂翰。三九已至,卻和暖如春蚤氏,著一層夾襖步出監(jiān)牢的瞬間甘耿,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 31,967評(píng)論 1 265
  • 我被黑心中介騙來(lái)泰國(guó)打工瞧捌, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留棵里,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 46,315評(píng)論 2 360
  • 正文 我出身青樓姐呐,卻偏偏與公主長(zhǎng)得像殿怜,于是被迫代替她去往敵國(guó)和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子曙砂,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 43,486評(píng)論 2 348