成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

推薦一款Kubernetes YAML文件靜態分析工具KubeLinter

開源
2020年10月28日,StackRox 引入了一個名為 KubeLinter 的新開源工具,旨在識別 YAML 文件中的任何錯誤配置。

在 Kubernetes 的世界中,我們使用 YAML 文件,對其進行部署以創建各種 Kubernetes 對象,但挑戰在于編寫它們時是否遵循最佳實踐?我們使用的是正確的標準配置集嗎?在部署應用程序甚至 Helm 圖表之前,可以檢查 YAML 嗎?所有這些問題的答案都是肯定的,我們可以。2020年10月28日,StackRox 引入了一個名為 KubeLinter 的新開源工具,旨在識別 YAML 文件中的任何錯誤配置。

根據定義,KubeLinter 是一個靜態分析工具,用于檢查 Kubernetes YAML 文件和 Helm 圖表,以確保其中所代表的應用程序遵循最佳實踐。將 YAML 文件提供給該工具后,它將通過內置檢查運行,然后詳細報告任何錯誤以及解決這些錯誤的補救措施。關于此工具的最好之處在于它是可配置和可擴展的:可以啟用或禁用內置檢查,并且您可以定義和使用自己的自定義檢查。

用法

我將在 Mac 上安裝 KubeLinter,但只需下載適用于您操作系統的發行版,即可將相同的說明用于Linux。

你可以從https://github.com/stackrox/kube-linter/releases/下載 KubeLinter CLI,如下所示: 

  1. $ curl -LO https://github.com/stackrox/kube-linter/releases/download/0.1.1/kube-linter-darwin.zip  
  2. $ unzip kube-linter-darwin.zip  
  3. $ mv kube-linter /usr/local/bin  
  4. #check if it's working  
  5. $ kube-linter version  
  6. 0.1.1 

現在,為了簡單地檢查單個 YAML 文件,只需提供 YAML 文件名。假設 deploy.yaml 您要檢查以下文件,以檢查其當前目錄中保存的最佳安全性和配置做法: 

  1. apiVersion: apps/v1  
  2. kind: Deployment  
  3. metadata:  
  4.   name: portainer  
  5.   namespace: portainer 
  6.   labels:  
  7.     io.portainer.kubernetes.application.stack: portainer  
  8.     app.kubernetes.io/name: portainer  
  9.     app.kubernetes.io/instance: portainer  
  10.     app.kubernetes.io/version: "2.0.0"  
  11. spec:  
  12.   replicas: 1  
  13.   strategy:  
  14.     type: "Recreate"  
  15.   selector:  
  16.     matchLabels:  
  17.       app.kubernetes.io/name: portainer  
  18.       app.kubernetes.io/instance: portainer  
  19.   template:  
  20.     metadata:  
  21.       labels: 
  22.          app.kubernetes.io/name: portainer  
  23.         app.kubernetes.io/instance: portainer  
  24.     spec:  
  25.       serviceAccountName: portainer-sa-clusteradmin  
  26.       volumes:  
  27.          - name: "data"  
  28.            persistentVolumeClaim:  
  29.              claimName: portainer  
  30.       containers:  
  31.         - name: portainer  
  32.           image: "portainer/portainer-ce:latest"  
  33.           imagePullPolicy: IfNotPresent  
  34.           args:  [ '--tunnel-port','30776' ]  
  35.           volumeMounts:  
  36.             - name: data  
  37.               mountPath: /data  
  38.           ports:  
  39.             - name: http  
  40.               containerPort: 9000  
  41.               protocol: TCP  
  42.             - name: tcp-edge  
  43.               containerPort: 8000  
  44.               protocol: TCP  
  45.           livenessProbe:  
  46.             httpGet:  
  47.               path: /  
  48.               port: 9000  
  49.           readinessProbe:  
  50.             httpGet:  
  51.               path: /  
  52.               port: 9000  
  53.           resources:  
  54.             {} 

讓我們進行測試 kube-linter lint deploy.yaml。我們應該得到如下輸出: 

  1. deploy.yaml: (object: portainer/portainer apps/v1, Kind=Deployment) container "portainer" does not have a read-only root file system (check: no-read-only-root-fs, remediation: Set readOnlyRootFilesystem to true in your container's securityContext.) 
  2. deploy.yaml: (object: portainer/portainer apps/v1, Kind=Deployment) serviceAccount "portainer-sa-clusteradmin" not found (check: non-existent-service-account, remediation: Make sure to create the service account, or to refer to an existing service account.) 
  3. deploy.yaml: (object: portainer/portainer apps/v1, Kind=Deployment) container "portainer" is not set to runAsNonRoot (check: run-as-non-root, remediation: Set runAsUser to a non-zero number, and runAsNonRoot to true, in your pod or container securityContext. See https://kubernetes.io/docs/tasks/configure-pod-container/security-context/ for more details.) 
  4. deploy.yaml: (object: portainer/portainer apps/v1, Kind=Deployment) container "portainer" has cpu request 0 (check: unset-cpu-requirements, remediation: Set your container's CPU requests and limits depending on its requirements. See https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/#requests-and-limits for more details.) 
  5. deploy.yaml: (object: portainer/portainer apps/v1, Kind=Deployment) container "portainer" has cpu limit 0 (check: unset-cpu-requirements, remediation: Set your container's CPU requests and limits depending on its requirements. See https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/#requests-and-limits for more details.) 
  6. deploy.yaml: (object: portainer/portainer apps/v1, Kind=Deployment) container "portainer" has memory request 0 (check: unset-memory-requirements, remediation: Set your container's memory requests and limits depending on its requirements. See https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/#requests-and-limits for more details.) 
  7. deploy.yaml: (object: portainer/portainer apps/v1, Kind=Deployment) container "portainer" has memory limit 0 (check: unset-memory-requirements, remediation: Set your container's memory requests and limits depending on its requirements. See https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/#requests-and-limits for more details.) 
  8. Error: found 7 lint errors 

檢測類型

如您所見,YAML 文件中發現了錯誤,每個錯誤都有明確的補救步驟。

如果您想看一下內置檢查,可以在https://github.com/stackrox/kube-linter/blob/main/docs/genic/checks.md中列出所有這些檢查,或者也可以使用 KubeLinter 查看清單: 

  1. $ kube-linter checks list  
  2. Name: dangling-service  
  3. Description: Alert on services that don't have any matching deployments  
  4. Remediation: Make sure your service's selector correctly matches the labels on one of your deployments.  
  5. Template: dangling-service  
  6. Parameters: map[]  
  7. Enabled by default: true  
  8. ------------------------------  
  9. Name: default-service-account  
  10. Description: Alert on pods that use the default service account  
  11. Remediation: Create a dedicated service account for your pod. See https://kubernetes.io/docs/tasks/configure-pod-container/configure-service-account/ for more details. 
  12. Template: service-account  
  13. Parameters: map[serviceAccount:^(|default)$]  
  14. Enabled by default: false  
  15.  
  16.  
  17.  
  18. and many more 

忽略檢測

您可以使用以下注釋忽略針對 YAML 文件的特定檢查,也可以根據需要忽略檢查組: 

  1. ignore-check.kube-linter.io/<check-name> 

例如: 

  1. ignore-check.kube-linter.io/unset-cpu-requirements 

您可以像上面這樣在上面的部署文件示例中添加忽略檢查規則: 

  1. metadata:  
  2.   name: portainer  
  3.   namespace: portainer  
  4.   labels: 
  5.      io.portainer.kubernetes.application.stack: portainer  
  6.     app.kubernetes.io/name: portainer  
  7.     app.kubernetes.io/instance: portainer  
  8.     app.kubernetes.io/version: "2.0.0"  
  9.   annotations:  
  10.     ignore-check.kube-linter.io/unset-cpu-requirements : "cpu requirements not required" 

現在,當您 kube-linter lint deploy.yaml 再次運行時,您應該不會看到與 CPU 要求相關的錯誤提示。

使用配置運行

KubeLinter 也可以使用配置運行,您可以在其中提供要包含/排除的所有檢測信息。以下是存儲庫中的示例配置: 

  1. # customChecks defines custom checks.  
  2. customChecks:  
  3. - name: "required-label-app"  
  4.   template: "required-label"  
  5.   params:  
  6.     key: "app"  
  7. checks: 
  8.    # if doNotAutoAddDefaults is true, default checks are not automatically added.  
  9.   doNotAutoAddDefaults: false  
  10.   # addAllBuiltIn, if set, adds all built-in checks. This allows users to  
  11.   # explicitly opt-out of checks that are not relevant using Exclude.  
  12.   # Takes precedence over doNotAutoAddDefaults, if both are set.  
  13.   addAllBuiltIn: false  
  14.   # include explicitly adds checks, by name. You can reference any of the built-in checks.  
  15.   # Note that customChecks defined above are included automatically.  
  16.   include:  
  17.   - "required-label-owner"  
  18.   # exclude explicitly excludes checks, by name. exclude has the highest priority: if a check is  
  19.   # in exclude, then it is not considered, even if it is in include as well.  
  20.   exclude:  
  21.     - "privileged" 

如果你運行kubelinter --config config lint deploy.yaml,其中 config 與上述配置的文件,你應該可以看到添加了需要標簽的檢查:

deploy.yaml: (object: portainer/portainer apps/v1, Kind=Deployment) no label matching "owner=<any>" found (check: required-label-owner, remediation: Add an email annotation to your object with information about the object's owner.)

當內置到 CI 管道中時,KubeLinter 可以證明是非常有用的工具。可以檢查和驗證推送到存儲庫中的編排文件,以獲取最佳實踐和安全考慮,并在檢測到問題時生成警報。

這樣,可以將部署到集群的應用程序進行健康的就緒檢查。該項目處于 Alpha 階段,但有望作為 CI 集成工具在實際部署到生產之前驗證所有部署。 

 

責任編輯:龐桂玉 來源: 奇妙的Linux世界
相關推薦

2021-07-29 06:37:55

KubernetesKubeLinter工具

2021-04-22 09:20:20

KubernetesKubectl FlaLinux

2016-03-29 14:54:36

2021-06-09 09:52:29

開源Pyroscope代碼

2025-04-07 08:10:00

2020-02-17 07:20:22

SSH遠程連接工具Linux

2024-01-25 10:40:11

AutoProfil開源分析工具

2020-12-03 09:33:58

前端開發工具

2022-06-28 07:14:23

WizTree磁盤文件清理

2020-12-15 15:08:17

工具Java線程

2020-12-15 07:54:40

工具Hutoolgithub

2024-02-20 07:32:18

Rsync遠程同步工具傳輸數據

2018-11-26 14:30:08

Python開發工具編程語言

2019-02-25 10:18:43

工具代碼測試

2019-07-22 09:24:54

LinuxMySQL數據庫

2019-08-02 14:45:22

阿里Java命令

2022-07-04 08:48:36

KubernetesDatreeLinux

2020-11-12 10:00:56

Kubernetes工具Linux

2021-11-01 05:53:08

Doldrums逆向工程分析工具安全工具

2022-06-20 08:58:25

Obsidian筆記工具
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 亚洲免费精品 | 国产精品成人一区二区三区 | 黄色网址在线免费观看 | 欧美精品一区二区三区在线 | 国产精品视频网站 | 青春草国产 | 中文在线一区二区 | 高清欧美性猛交xxxx黑人猛交 | 日韩欧美三级 | 91视频免费 | 亚洲欧美视频在线观看 | 国产午夜精品一区二区三区四区 | 国产99视频精品免视看9 | 国产成人99久久亚洲综合精品 | 中文字幕日韩专区 | xxxcom在线观看 | 极品的亚洲 | 成人h免费观看视频 | 国产在线不卡 | 国产一区二区三区www | 国产成人精品久久二区二区91 | www国产成人 | 国产高清在线观看 | 视频一区在线 | 欧美精品第一页 | 青青久久久| 国产激情毛片 | 欧美 中文字幕 | 日韩成人免费中文字幕 | 亚洲国产精品久久 | 精品久久久久久红码专区 | 午夜视频免费在线观看 | 久草网址| 欧美日韩美女 | 日本三级日产三级国产三级 | 澳门永久av免费网站 | 日韩在线观看一区 | 欧美视频三区 | 男人阁久久| 国产色| 欧美成人精品在线观看 |