博客 / 詳情

返回

Openshift環境安裝K8S軟件管理工具Helm

參考:

  • Make a Kubernetes Operator in 15 minutes with Helm
  • Deploy Monocular on OpenShift
  • Helm中文指南;
  • 使用Helm管理kubernetes應用;
  • https://helm.sh/docs/using_he...

參考官方文檔https://docs.helm.sh/using_he...Openshift環境安裝Helm Tiller時其指向Bloghttps://blog.openshift.com/ge...

Helm works straightforward on OpenShift Online, OpenShift Dedicated, OpenShift Container Platform (version >= 3.6) or OpenShift Origin (version >= 3.6). To learn more read this blog post.

安裝helm客户端,版本參考https://github.com/helm/helm/...。如下所示,在m01主機安裝當前最新文檔版v2.12.3

cd /tmp
curl -s https://storage.googleapis.com/kubernetes-helm/helm-v2.12.3-linux-amd64.tar.gz \
     | tar xz
sudo mv linux-amd64/helm /usr/local/bin
sudo chmod a+x /usr/local/bin/helm

可選。默認stable倉庫為https://kubernetes-charts.sto...,但此網被牆導致無法連接,可刪掉並添加其他第三方倉庫,如:

helm repo remove stable
# 將阿里雲倉庫設置為stable倉庫:
helm init --client-only --stable-repo-url \
                          https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts
                          
# 或為倉庫設置不同的名稱:
helm repo add ali-stable https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts
helm repo add ali-incubator \
              https://aliacs-app-catalog.oss-cn-hangzhou.aliyuncs.com/charts-incubator
helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo list

安裝tiller

  1. 創建項目:

    oc new-project helm-tiller
    oc project helm-tiller
    export TILLER_NAMESPACE=helm-tiller
  2. 默認鏡像為gcr.io/kubernetes-helm/tiller,因網絡原因,換成registry.cn-hangzhou.aliyuncs.com/google_containers/tiller

    export TILLER_NAMESPACE=helm-tiller
    oc process -f https://github.com/openshift/origin/raw/master/examples/helm/tiller-template.yaml \
      -p TILLER_NAMESPACE="${TILLER_NAMESPACE}" -p HELM_VERSION=v2.12.3 | \
      perl -i -ne 's#gcr.io/kubernetes-helm#registry.cn-hangzhou.aliyuncs.com/google_containers#g;print'  | \
      oc create -f -
  3. 測試:

    % helm version
    Client: &version.Version{SemVer:"v2.12.3", GitCommit:"eecf22f77df5f65c823aacd2dbd30ae6c65f186e", GitTreeState:"clean"}
    Server: &version.Version{SemVer:"v2.12.3", GitCommit:"eecf22f77df5f65c823aacd2dbd30ae6c65f186e", GitTreeState:"clean"}
    % helm list

注意helm init --dry-run -o yaml僅輸出yaml文件而不會實際執行,觀察可發現以上使用template創建tillerhelm init創建tiller的區別有:

  • helm init沒有為tiller配置SARBAC權限綁定,且默認創建在kube-system名稱空間中(--tiller-namespace kube-system);
  • helm inittiller創建了service,但template未創建,後續我們需要額外創建,此Servicekubeapps中被使用;

賦權:

# 僅賦予在本項目內的edit權限:
% oc policy add-role-to-user edit "system:serviceaccount:${TILLER_NAMESPACE}:tiller"
role "edit" added: "system:serviceaccount:helm-tiller:tiller"

# 為使helm可管理整個集羣,即在其他project項目也有權限,賦予:
oc adm policy add-cluster-role-to-user cluster-admin \
       system:serviceaccount:${TILLER_NAMESPACE}:tiller

若是K8S原生集羣,則使用如下命令創建SA並賦權:

kubectl -n helm-tiller create sa tiller
kubectl create clusterrolebinding tiller --clusterrole cluster-admin \
                                         --serviceaccount=helm-tiller:tiller

為便於執行helm,將TILLER_NAMESPACE添加到環境變量中:

echo export TILLER_NAMESPACE=helm-tiller >> .bash_profile

創建service,此servicekubeapps程序所使用。

oc create -f - <<EOF
apiVersion: v1
kind: Service
metadata:
  creationTimestamp: null
  labels:
    app: helm
    name: tiller
  name: tiller-deploy
  namespace: helm-tiller
spec:
  ports:
  - name: tiller
    port: 44134
    targetPort: tiller
  selector:
    app: helm
    name: tiller
  type: ClusterIP
status:
  loadBalancer: {}
EOF
user avatar niruoanhaobianshiqingtian_5e03350be8f72 頭像 u_15533008 頭像 trophawk 頭像 guoxiaoyu 頭像 portlouis 頭像
5 位用戶收藏了這個故事!

發佈 評論

Some HTML is okay.