Browse Source

Add Secret to chart

zhanghongtong 5 years atrás
parent
commit
bff88c104e

+ 2 - 2
deploy/chart/kuiper/Chart.yaml

@@ -1,6 +1,6 @@
 apiVersion: v2
 name: kuiper
-description: A Helm chart for Kubernetes
+description: A lightweight IoT edge analytic software
 
 # A chart can be either an 'application' or a 'library' chart.
 #
@@ -14,7 +14,7 @@ type: application
 
 # This is the chart version. This version number should be incremented each time you make changes
 # to the chart and its templates, including the app version.
-version: 0.1.0
+version: 0.0.3
 
 # This is the version number of the application being deployed. This version number should be
 # incremented each time you make changes to the application.

+ 125 - 28
deploy/chart/kuiper/README_zh.md

@@ -23,40 +23,62 @@ Kuiper 可以通过 Helm chart 部署在 k3s / k8s 集群上。
   $ export KUBECONFIG=/etc/rancher/k3s/k3s.yaml
   ```
 
-## 通过 Helm 部署 Kuiper
+## 获取 Kuiper Helm Chart
 
-+ 获取项目代码
++ 可以通过一下两种方法的任意一种获取 Kuiper Helm Chart,本文以使用 `git clone` 拉取代码的方式为例讲解。
 
-  ```
-  $ git clone https://github.com/emqx/kuiper
-  $ cd kuiper/deploy/chart/kuiper
-  ```
+  + Git clone
+
+    ```
+    $ git clone https://github.com/emqx/kuiper
+    $ cd kuiper/deploy/chart/kuiper
+    ```
+
+  + Helm repo (TODO)
+
+    + 添加Helm repo
+
+      ```
+      $ helm repo add emqx https://repos.emqx.io/charts
+      ```
 
-+ 可以通过编辑 `values.yaml` 文件修改部署配置
+    + 查询 Kuiper
+
+      ```
+      helm search kuiper
+      NAME     		CHART VERSION	APP VERSION  	DESCRIPTION
+      emqx/kuiper	0.0.3	        0.0.3	        A lightweight IoT edge analytic software
+      ```
+
++ 可以通过编辑 `values.yaml` 文件或使用 `helm install --set` 命令编辑 Kuiper Helm Chart 的配置
 
   ##### Kuiper Helm Chart 配置项
 
-  | 参数                        | 描述                                                         | Default Value            |
-  | --------------------------- | ------------------------------------------------------------ | ------------------------ |
-  | `replicaCount`              | 部署kuiper数量                                               | 1                        |
-  | `image.repository`          | 拉取镜像名称                                                 | emqx/kuiper              |
-  | `image.pullPolicy`          | 拉取镜像策略                                                 | IfNotPresent             |
-  | `persistence.enabled`       | 是否启用 PVC                                                 | false                    |
-  | `persistence.storageClass`  | Storage class 名称                                           | `nil`                    |
-  | `persistence.existingClaim` | PV 名称                                                      | ""                       |
-  | `persistence.accessMode`    | PVC 访问模式                                                 | ReadWriteOnce            |
-  | `persistence.size`          | PVC 容量                                                     | 20Mi                     |
-  | `resources`                 | CPU/内存资源                                                 | {}                       |
-  | `nodeSelector`              | 节点选择                                                     | {}                       |
-  | `tolerations`               | 污点容忍                                                     | []                       |
-  | `affinity`                  | 节点亲和性                                                   | {}                       |
-  | `mqtt.servers`              | mqtt服务器的代理地址                                         | `[tcp://127.0.0.1:1883]` |
-  | `mqtt.qos`                  | 消息转发的服务质量                                           | 1                        |
-  | `mqtt.sharedSubscription`   | 是否使用共享订阅                                             | true                     |
-  | `mqtt.username`             | 连接用户名                                                   |                          |
-  | `mqtt.password`             | 连接密码                                                     |                          |
-  | `mqtt.certificationPath`    | 证书路径。可以为绝对路径,也可以为相对路径。如果指定的是相对路径,那么父目录为执行`server`命令的路径。比如,如果你在`/var/kuiper` 中运行 `bin/server` ,那么父目录为 `/var/kuiper`; 如果运行从`/var/kuiper/bin`中运行`./server`,那么父目录为 `/var/kuiper/bin`。 |                          |
-  | `mqtt.privateKeyPath`       | 私钥路径。可以为绝对路径,也可以为相对路径。更详细的信息,请参考 `certificationPath`. |                          |
+  | 参数                           | 描述                                | Default Value            |
+  | ------------------------------ | ----------------------------------- | ------------------------ |
+  | `replicaCount`                 | 部署kuiper数量                      | 1                        |
+  | `image.repository`             | 拉取镜像名称                        | emqx/kuiper              |
+  | `image.pullPolicy`             | 拉取镜像策略                        | IfNotPresent             |
+  | `persistence.enabled`          | 是否启用 PVC                        | false                    |
+  | `persistence.storageClass`     | Storage class 名称                  | `nil`                    |
+  | `persistence.existingClaim`    | PV 名称                             | ""                       |
+  | `persistence.accessMode`       | PVC 访问模式                        | ReadWriteOnce            |
+  | `persistence.size`             | PVC 容量                            | 20Mi                     |
+  | `resources`                    | CPU/内存资源                        | {}                       |
+  | `nodeSelector`                 | 节点选择                            | {}                       |
+  | `tolerations`                  | 污点容忍                            | []                       |
+  | `affinity`                     | 节点亲和性                          | {}                       |
+  | `mqtt.servers`                 | mqtt服务器的代理地址                | `[tcp://127.0.0.1:1883]` |
+  | `mqtt.qos`                     | 消息转发的服务质量                  | 1                        |
+  | `mqtt.sharedSubscription`      | 是否使用共享订阅                    | true                     |
+  | `mqtt.username`                | 连接用户名                          |                          |
+  | `mqtt.password`                | 连接密码                            |                          |
+  | `mqtt.certificationSecretName` | 通过证书文件创建的 Secre 资源的名字 |                          |
+  | `mqtt.privateKeySecretName`    | 通过私钥文件创建的 Secre 资源的名字 |                          |
+  | `mqtt.certificationPath`       | 证书路径。必须是绝对路径。          |                          |
+  | `mqtt.privateKeyPath`          | 私钥路径。必须绝对路径。            |                          |
+
+## 通过 Helm 部署 Kuiper
 
 #### 快速部署Kuiper
 
@@ -78,6 +100,10 @@ Kuiper 可以通过 Helm chart 部署在 k3s / k8s 集群上。
   $ kubectl get pods
   NAME       READY   STATUS    RESTARTS   AGE
   my-kuiper-0   1/1     Running   0          19s
+
+  $ kubectl exec -it  my-kuiper-0 sh
+  /kuiper # ./bin/cli
+  Connecting to 127.0.0.1:20498...
   ```
 
 #### 部署持久化的 Kuiper
@@ -107,4 +133,75 @@ Kuiper 可以通过 Helm chart 部署在 k3s / k8s 集群上。
   $ kubectl get pods
   NAME       READY   STATUS    RESTARTS   AGE
   my-kuiper-0   1/1     Running   0          19s
+
+  $ kubectl exec -it  my-kuiper-0 sh
+  /kuiper # ./bin/cli
+  Connecting to 127.0.0.1:20498...
+  ```
+
+#### 部署Kuiper并使用证书
+
++ 使用 `kubectl create secret` 将证书文件和私钥创建成 Secret 资源,`kubectl create secret` 命令的语法如下:
+
+  ```
+  $ kubectl create secret generic your-secret-name --from-file=/path/to/file
+  ```
+
+  创建证书文件 Secret 资源:
+
+  ```
+  $ kubectl create secret generic client-cert --from-file=certs/client-cert.pem
+  ```
+
+  创建私钥文件 Secret 资源:
+
+  ```
+  $ kubectl create secret generic client-key --from-file=certs/client-key.pem
   ```
+
+  查看 Secret 资源:
+
+  ```
+  $ kubectl get secret
+  NAME                                         TYPE                                  DATA   AGE
+  client-cert                                  Opaque                                1      25m
+  client-key                                   Opaque                                1      24m
+  ```
+
++ 编辑 `values.yaml` 文件
+
+  + 设置 `mqtt.certificationSecretName` 为证书文件 Secret 资源: `mqtt.certificationSecretName: client-cert`
+  + 设置 `mqtt.privateKeySecretName` 为私钥文件 Secret 资源:`mqtt.privateKeySecretName: client-key`
+  + 设置证书文件部署路径:`mqtt.certificationPath: /var/kuiper/certificate.pem`
+  + 设置私钥文件部署路径:`mqtt.privateKeyPath: /var/kuiper/private.pem.key`
+
++ 使用 Helm 部署 Kuiper
+
+  ```
+  $ helm install my-kuiper .
+  NAME: my-kuiper
+  LAST DEPLOYED: Mon Dec  9 09:56:32 2019
+  NAMESPACE: default
+  STATUS: deployed
+  REVISION: 1
+  TEST SUITE: None
+  ```
+
++ 部署成功
+
+  ```
+  $ kubectl get pods
+  NAME       READY   STATUS    RESTARTS   AGE
+  my-kuiper-0   1/1     Running   0          19s
+
+  $ kubectl exec -it my-kuiper-0 -- ls -al /var/kuiper
+  total 8
+  drwxr-xr-x    4 root     root          4096 Dec 10 02:23 .
+  drwxr-xr-x    1 root     root          4096 Dec 10 02:23 ..
+  drwxrwxrwt    3 root     root           100 Dec 10 02:23 certificate.pem
+  drwxrwxrwt    3 root     root           100 Dec 10 02:23 private.pem.key
+
+  $ kubectl exec -it  my-kuiper-0 sh
+  /kuiper # ./bin/cli
+  Connecting to 127.0.0.1:20498...
+  ```

+ 20 - 7
deploy/chart/kuiper/templates/StatefulSet.yaml

@@ -55,6 +55,16 @@ spec:
           items:
           - key: mqtt.yaml
             path: mqtt.yaml
+      {{- if .Values.mqtt.certificationSecretName }}
+      - name: kuiper-certification
+        secret:
+          secretName: {{ .Values.mqtt.certificationSecretName }}
+      {{- end }}
+      {{- if .Values.mqtt.privateKeySecretName }}
+      - name: kuiper-private-key
+        secret:
+          secretName: {{ .Values.mqtt.privateKeySecretName }}
+      {{- end }}
       containers:
         - name: kuiper
           image: "{{ .Values.image.repository }}:{{ .Chart.AppVersion }}"
@@ -65,6 +75,16 @@ spec:
           - name: mqtt
             mountPath: "/kuiper/etc/sources/mqtt.yaml"
             subPath: "mqtt.yaml"
+          {{ if .Values.mqtt.certificationSecretName  }}
+          - name: kuiper-certification
+            mountPath: {{ .Values.mqtt.certificationPath | default "/var/kuiper/certificate.pem" }}
+            readOnly: true
+          {{ end }}
+          {{ if .Values.mqtt.privateKeySecretName  }}
+          - name: kuiper-private-key
+            mountPath: {{ .Values.mqtt.privateKeyPath | default "/var/kuiper/private.pem.key" }}
+            readOnly: true
+          {{ end }}
           resources:
           {{- toYaml .Values.resources | nindent 12 }}
     {{- with .Values.nodeSelector }}
@@ -79,10 +99,3 @@ spec:
       tolerations:
         {{- toYaml . | nindent 8 }}
     {{- end }}
-
-          # readinessProbe:
-          #   httpGet:
-          #     path: /status
-          #     port: 8080
-          #   initialDelaySeconds: 5
-          #   periodSeconds: 5

+ 4 - 2
deploy/chart/kuiper/values.yaml

@@ -45,5 +45,7 @@ mqtt:
   servers: [tcp://127.0.0.1:1883]
   #username: user1
   #password: password
-  #certificationPath: /var/kuiper/xyz-certificate.pem
-  #privateKeyPath: /var/kuiper/xyz-private.pem.key
+  certificationSecretName: client-cert
+  privateKeySecretName: client-key
+  #certificationPath: /var/kuiper/certificate.pem
+  #privateKeyPath: /var/kuiper/private.pem.key