学习 Kubernetes helm 基础知识

目录结构

$ tree
.
├── Chart.yaml
├── templates
│   ├── deployment.yaml
│   └── service.yaml
└── values.yaml

无配置文件

文件配置

Chart.yaml

name: hello-world
version: 1.0.0

templates/deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: hello-world
spec:
  replicas: 1
  selector:
    matchLabels:
      app: hello-world
  template:
    metadata:
      labels:
        app: hello-world
    spec:
      containers:
      - name: hello-world
        image: nginx:latest
        ports:
        - containerPort: 80
          protocol: TCP

templates/service.yaml

apiVersion: v1
kind: Service
metadata:
  name: hello-world
spec:
  type: NodePort
  ports:
  - port: 80
    targetPort: 80
    protocol: TCP
  selector:
    app: hello-world

创建 Release

$ helm install . --generate-name
NAME: chart-1590978912
LAST DEPLOYED: Mon Jun  1 10:35:12 2020
NAMESPACE: phishing
STATUS: deployed
REVISION: 1
TEST SUITE: None

$ helm install nginx .
NAME: nginx
LAST DEPLOYED: Mon Jun  1 11:12:38 2020
NAMESPACE: phishing
STATUS: deployed
REVISION: 1
TEST SUITE: None

有配置文件

文件配置

values.yaml

image:
  repository: nginx
  tag: 'latest'

templates/deployment.yaml

image: :

查看 Release

列出已经部署的 Release

$ helm ls

1590980023493

查询一个特定的 Release 的状态

$ helm status chart-1590978912
NAME: chart-1590978912
LAST DEPLOYED: Mon Jun  1 10:35:12 2020
NAMESPACE: phishing
STATUS: deployed
REVISION: 1
TEST SUITE: None

移除所有与这个 Release 相关的 Kubernetes 资源

$ helm delete chart-1590978912
release "chart-1590978912" uninstalled

Debug

使用模板动态生成K8s资源清单,非常需要能提前预览生成的结果。

使用–dry-run –debug 选项来打印出生成的清单文件内容,而不执行部署

$ helm install nginx . --dry-run --debug --set image.tag=latest