雲計算_K8s集群Helm離線部署Chart


K8s

 Promethues 
 Grafana
 helm
 專業的容器服務除了收集容器性能指標以外(如cadvisor、promethues),還需要重點保留現場的容器拓撲快照(如kur8),以方便進行問題場景還原
 離線安裝Chart,需要在外網的情況下下載鏡像和chart文件,以及依賴的Chart文件和鏡像,
  注意: 使用Kind的時候,注意 kind load docker-image nginx nginx:test  通過 kind load 將客戶機上的鏡像加載到 K8S 環境中去,
  否則,在kubectl get pods 會 顯示 生成的Pod 處於這種狀態  ErrImageNeverPull	策略禁止拉取鏡像

Helm

Helm 運行這個install時候,
最少要傳倆參數,你要定一個release name,以及你要裝的chart是啥。
自定義配置選項
  安裝過程中有兩種方法可以傳遞配置數據:
     --values(或-f):指定帶有覆蓋的YAML文件。這可以多次指定,最右邊的文件優先 --values使用,先將修改的變量寫到一個文件中
     --set:在命令行上指定替代。如果兩者都用,--set優先級高
	   --set 選項使用 0 或多個 name/value 對。最簡單的用法類似於:--set name=value,等價於如下 YAML 格式:
$ helm install happy-panda stable/mariadb
helm dependency update .
helm install my-spark . 
helm dependency update
    該命令驗證存儲在'charts/'目錄中的'Chart.yaml'文件描述的所需chart以及所需版本。 它會拉取滿足依賴的最新chart並清理舊依賴
helm
     -n, --namespace string            namespace scope for this request

Chart格式說明

Chart.yaml 文件包含了該chart的描述。
charts/目錄 可以 包含其他的chart(稱之為 子chart)

1.Chart.yaml

 apiVersion   name  version
  chart 的名稱、版本、維護者、依賴(即子 chart
 A chart can be either an 'application' or a 'library' chart.
    type :  application library
 聲明了 dependencies 的 chart 中
    執行helm dependency update或helm dependency build將會自動生成一個 Chart.lock 文件,
    且如果設置了依賴項的 repository,會到倉庫中查找並打包為 .tgz 文件下載到 
    charts/ 路徑下。
  There are two types: application and library. 
  Application is the default type and it is the standard chart which can be operated on fully. 
  The library chart provides utilities or functions for the chart builder. 
  A library chart differs from an application chart because it is not installable and usually doesn't contain any resource objects.
 
 Note: An application chart can be used as a library chart. 
 This is enabled by setting the type to library. 
 The chart will then be rendered as a library chart where all utilities and functions can be leveraged.
  All resource objects of the chart will not be rendered.
    
 dependencies:
   - name: apache
     version: 1.2.3
     repository: http://example.com/charts
   - name: mysql
     version: 3.2.1
     repository: http://another.example.com/charts
 
     name:Chart 名稱
     version:Chart 版本
     repository: Chart 倉庫 URL 地址

2.values.yaml

 imageRegistry: "quay.io/deis"
 dockerTag: "latest"
 pullPolicy: "Always"
 storage: "s3"		 
  修改  tag: 14.2.0-debian-10-r14 為自己的鏡像
 或者修改鏡像為 tag的鏡像  Usage:  docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]   docker tag bitnami/postgresql:11.11.0 bitnami/postgresql:14.2.0-debian-10-r14
 要約束 values.yaml 中的配置結構,可以創建一個 values.schema.json
  Always 總是拉取:首先獲取倉庫鏡像信息,如果倉庫中的鏡像與本地不同,那么倉庫中的鏡像會被拉取並覆蓋本地。如果倉庫中的鏡像與本地一致,那么不會拉取鏡像。 如果倉庫不可用,那么pod運行失敗。 
   IfNotPresent優先使用本地: 如果本地存在鏡像,則使用本地的, 不管倉庫是否可用。不管倉庫中鏡像與本地是否一致。
    Never 只使用本地鏡像,如果本地不存在,則pod運行失敗

自定義chart

helm create myapp

00.查看Chart.yaml中的 dependencies,把repository注釋掉,並手動下載對應的依賴
   Chart.yaml 中設置 dependencies 的用意。當我們依賴於別人提供的 chart,但在部署時又需要對其中的一些配置進行調整,
   這時候就可以通過在父 Chart.yaml 中設置能對應到子 chart 中 values.yaml 中的配置的配置項,來達到覆蓋子 chart 中配置值的目的。

01.下載
 https://github.com/bitnami/charts/tree/master/bitnami/common
02.打包  打包charts
 helm package common/ 
 tar xvf common.tgz
 移動到本項目的charts/ 目錄下
  等效 使用helm pull <chart-name>直接從倉庫中抓取對應的 chart 到 charts/ 下
03.
  helm dependency update .
  
 04.離線安裝
  #helm install my-release bitnami/postgresql
  本地安裝 cd ~/postgresql
  helm install my-release .
  
    ** Please be patient while the chart is being deployed **
    PostgreSQL can be accessed via port 5432 on the following DNS names from within your cluster:
        my-release-postgresql.default.svc.cluster.local - Read/Write connection
    
    To get the password for "postgres" run:
        export POSTGRES_PASSWORD=$(kubectl get secret --namespace default my-release-postgresql -o jsonpath="{.data.postgres-password}" | base64 --decode)
    
    To connect to your database run the following command:
        kubectl run my-release-postgresql-client --rm --tty -i --restart='Never' --namespace default --image docker.io/bitnami/postgresql:14.2.0-debian-10-r14 --env="PGPASSWORD=$POSTGRES_PASSWORD" \
          --command -- psql --host my-release-postgresql -U postgres -d postgres -p 5432
        > NOTE: If you access the container using bash, make sure that you execute "/opt/bitnami/scripts/entrypoint.sh /bin/bash" in order to avoid the error "psql: local user with ID 1001} does not exist"
    
    To connect to your database from outside the cluster execute the following commands:
        kubectl port-forward --namespace default svc/my-release-postgresql 5432:5432 &
        PGPASSWORD="$POSTGRES_PASSWORD" psql --host 127.0.0.1 -U postgres -d postgres -p 5432
    
  05.查看集群的鏡像
     helm  list

       06.查看安裝狀態

kubectl常用示例

  簡單部署:編寫配置文件--》使用“ kubectl create ”執行資源創建 
       kubectl create 命令,是先刪除所有現有的東西,重新根據yaml文件生成新的
	   kubectl apply  命令,根據配置文件里面列出來的內容,升級現有的
 Helm部署,並使用kubectl觀察部署是否失敗
 kubectl get命令提供有關Kubernetes中許多內容的信息,包括Pod,節點和名稱空間
    查看類命令
	 kubectl cluster-info
	
	kubectl get nodes -o wide
	kubectl get ns
	
	kubectl get pod -A 
	kubectl get pod
	kubectl get pod -n kube-system
    kubectl get pod -o wide
    kubectl get pods -o yaml
    kubectl get pods -o json
	
	##進入
	  kubectl exec:進入pod啟動的容器

Helm

Chart 代表着 Helm 包  
Repository(倉庫) 是用來存放和共享 charts 的地方
Release 是運行在 Kubernetes 集群中的 chart 的實例   

chart包 helm chart repo 
   https://artifacthub.io/  https://artifacthub.io/packages/search
   The Bitnami Library for Kubernetes   https://charts.bitnami.com/bitnam  https://github.com/bitnami/charts
   https://kubernetes-charts.storage.googleapis.com/
   bitnami by  VMware  
   
 Add repository --》 Install chart 
 https://dolphinscheduler.apache.org/zh-cn/docs/3.1.3/guide/start/docker
 https://dolphinscheduler.apache.org/zh-cn/docs/3.1.3/guide/installation/kubernetes
 
 helm repo add cetic https://cetic.github.io/helm-charts
 helm repo update
 helm install my-release cetic/postgresql
 
 
 $ helm repo add bitnami https://charts.bitnami.com/bitnami
 $ helm dependency update .
 $ helm install dolphinscheduler . --set image.tag=<version>
 
 

PostgreSQL 和 ZooKeeper 
apache/dolphinscheduler-tools
apache/dolphinscheduler-master
apache/dolphinscheduler-worker
apache/dolphinscheduler-api
apache/dolphinscheduler-alert-server
https://github.com/apache/dolphinscheduler/blob/dev/deploy/docker/docker-compose.yml
Docker Stack,它用於向swarm集群部署完整的應用程序堆棧-Stack是集群下的Compose
docker pull apache/dolphinscheduler:3.1.3

參考

 Pod鏡像拉取策略imagePullPolicy https://www.cnblogs.com/orchidzjl/p/11712142.html	
 https://www.cnblogs.com/zhanglianghhh/p/13467038.html	 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM