|
| 1 | +# Kubernetes Install |
| 2 | + |
| 3 | +Any deployment on Kubernetes is going to be specific to the environment and requirements of the solution. The following are examples that can be adopted to fit specific needs. |
| 4 | + |
| 5 | +## Fixed Configuration |
| 6 | + |
| 7 | +If you have an existing `device.yml` file containing a set of Device Agent credentials. |
| 8 | + |
| 9 | +```bash |
| 10 | +kubectl create secret generic device-one-secret --from-file=device.yml=./device.yml |
| 11 | +``` |
| 12 | + |
| 13 | +The following manifest will create a Deployment and Service for a device using the supplied Secret as it's credentials |
| 14 | + |
| 15 | +```yaml |
| 16 | +apiVersion: apps/v1 |
| 17 | +kind: Deployment |
| 18 | +metadata: |
| 19 | + name: device-one |
| 20 | + labels: |
| 21 | + app: device-one |
| 22 | +spec: |
| 23 | + replicas: 1 |
| 24 | + revisionHistoryLimit: 10 |
| 25 | + selector: |
| 26 | + matchLabels: |
| 27 | + app: device-one |
| 28 | + template: |
| 29 | + metadata: |
| 30 | + labels: |
| 31 | + app: device-one |
| 32 | + spec: |
| 33 | + containers: |
| 34 | + - name: device-one |
| 35 | + image: flowfuse/device-agent:latest |
| 36 | + ports: |
| 37 | + - containerPort: 1880 |
| 38 | + volumeMounts: |
| 39 | + - name: config |
| 40 | + mountPath: "/opt/flowfuse-device/device.yml" |
| 41 | + subPath: "device.yml" |
| 42 | + readOnly: true |
| 43 | + resources: |
| 44 | + limits: |
| 45 | + cpu: 1000m |
| 46 | + memory: 256Mi |
| 47 | + requests: |
| 48 | + cpu: 500m |
| 49 | + memory: 128Mi |
| 50 | + volumes: |
| 51 | + - name: config |
| 52 | + secret: |
| 53 | + secretName: device-one-secret |
| 54 | +--- |
| 55 | +apiVersion: v1 |
| 56 | +kind: Service |
| 57 | +metadata: |
| 58 | + name: device-one-service |
| 59 | +spec: |
| 60 | + selector: |
| 61 | + app: device-one |
| 62 | + ports: |
| 63 | + - protocol: TCP |
| 64 | + port: 1880 |
| 65 | + targetPort: 1880 |
| 66 | +``` |
| 67 | +
|
| 68 | +## Automatic Provisioning |
| 69 | +
|
| 70 | +Using a FlowFuse Provisioning Token to automatically configure a new Device Agent on deployment. |
| 71 | +
|
| 72 | +Because the Device Agent will need to re-write the `device.yml` file it can no longer be stored in a Secret and a PersistentVolume must be used for each instance of the Device Agent. |
| 73 | + |
| 74 | +A Secret is used to hold the initial `device.yml` which contains the provisioning token. |
| 75 | + |
| 76 | +```bash |
| 77 | +kubectl create secret generic device-provisioning-secret --from-file=device.yml=./device.yml |
| 78 | +``` |
| 79 | + |
| 80 | +The following manifest will create a Deployment, Service and PVC for a device using the supplied Secret as the source of the Provisioning token. |
| 81 | + |
| 82 | +The PVC will be used to store the updated `device.yml` and the Node-RED nodes installed by the Remote Instance. |
| 83 | + |
| 84 | +```yaml |
| 85 | +apiVersion: apps/v1 |
| 86 | +kind: Deployment |
| 87 | +metadata: |
| 88 | + name: device-one |
| 89 | + labels: |
| 90 | + app: device-one |
| 91 | +spec: |
| 92 | + replicas: 1 |
| 93 | + revisionHistoryLimit: 10 |
| 94 | + selector: |
| 95 | + matchLabels: |
| 96 | + app: device-one |
| 97 | + template: |
| 98 | + metadata: |
| 99 | + labels: |
| 100 | + app: device-one |
| 101 | + spec: |
| 102 | + initContainers: |
| 103 | + - name: config-copy |
| 104 | + image: busybox:latest |
| 105 | + command: |
| 106 | + - "/bin/sh" |
| 107 | + - "-c" |
| 108 | + - "if [ ! -f /opt/flowfuse-device/device.yml ]; then cp /tmp/device.yml /opt/flowfuse-device/device.yml; fi" |
| 109 | + volumeMounts: |
| 110 | + - name: config |
| 111 | + mountPath: "/opt/flowfuse-device" |
| 112 | + - name: initial-config |
| 113 | + mountPath: "/tmp/device.yml" |
| 114 | + subPath: "device.yml" |
| 115 | + readOnly: true |
| 116 | + containers: |
| 117 | + - name: device-one |
| 118 | + image: flowfuse/device-agent:latest |
| 119 | + ports: |
| 120 | + - containerPort: 1880 |
| 121 | + volumeMounts: |
| 122 | + - name: config |
| 123 | + mountPath: "/opt/flowfuse-device" |
| 124 | + resources: |
| 125 | + limits: |
| 126 | + cpu: 1000m |
| 127 | + memory: 256Mi |
| 128 | + requests: |
| 129 | + cpu: 500m |
| 130 | + memory: 128Mi |
| 131 | + volumes: |
| 132 | + - name: initial-config |
| 133 | + secret: |
| 134 | + secretName: device-provisioning-secret |
| 135 | + - name: config |
| 136 | + persistentVolumeClaim: |
| 137 | + claimName: device-one-pvc |
| 138 | + |
| 139 | +--- |
| 140 | +apiVersion: v1 |
| 141 | +kind: Service |
| 142 | +metadata: |
| 143 | + name: device-one-service |
| 144 | +spec: |
| 145 | + selector: |
| 146 | + app: device-one |
| 147 | + ports: |
| 148 | + - protocol: TCP |
| 149 | + port: 1880 |
| 150 | + targetPort: 1880 |
| 151 | +--- |
| 152 | +apiVersion: v1 |
| 153 | +kind: PersistentVolumeClaim |
| 154 | +metadata: |
| 155 | + name: device-one-pvc |
| 156 | +spec: |
| 157 | + accessModes: |
| 158 | + - ReadWriteOnce |
| 159 | + resources: |
| 160 | + requests: |
| 161 | + storage: 1Gi |
| 162 | +``` |
0 commit comments