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

參考:html

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

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.3git

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...,但此網被牆致使沒法鏈接,可刪掉並添加其餘第三方倉庫,如:github

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

安裝tillershell

  1. 建立項目:api

    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/tillerbash

    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的區別有:app

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

賦權:curl

# 僅賦予在本項目內的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
相關文章
相關標籤/搜索