|
| 1 | +## Requirements |
| 2 | + |
| 3 | +Before proceeding, please ensure that you have an OpenShift cluster running K8s |
| 4 | +1.19+ (OpenShift 4.7+) and have Helm 3.5+ installed. In addition, you'll need to |
| 5 | +install the OpenShift CLI (`oc`) to authenticate to your cluster and create OpenShift |
| 6 | +resources. |
| 7 | + |
| 8 | +You'll also want to install the [latest version of Coder](https://github.com/coder/coder/releases/latest) |
| 9 | +locally in order to log in and manage templates. |
| 10 | + |
| 11 | +## Install Coder with OpenShift |
| 12 | + |
| 13 | +### 1. Authenticate to OpenShift and create a Coder project |
| 14 | + |
| 15 | +Run the following command to login to your OpenShift cluster: |
| 16 | + |
| 17 | +```console |
| 18 | +oc login <cluster-url> |
| 19 | +``` |
| 20 | + |
| 21 | +This will configure your local `~/.kube/config` file with the cluster credentials |
| 22 | +needed when installing Coder via `helm`. |
| 23 | + |
| 24 | +Next, you will run the below command to create a project for Coder: |
| 25 | + |
| 26 | +```console |
| 27 | +oc new-project coder |
| 28 | +``` |
| 29 | + |
| 30 | +### 2. Configure SecurityContext values |
| 31 | + |
| 32 | +Depending upon your configured Security Context Constraints (SCC), you'll need to set |
| 33 | +the following `securityContext` values in the Coder Helm chart: |
| 34 | + |
| 35 | +```yaml |
| 36 | +coder: |
| 37 | + securityContext: |
| 38 | + runAsNonRoot: true |
| 39 | + runAsUser: 1000 |
| 40 | + runAsGroup: 1000 |
| 41 | + readOnlyRootFilesystem: true |
| 42 | + seccompProfile: |
| 43 | + type: RuntimeDefault |
| 44 | + allowPrivilegeEscalation: false |
| 45 | +``` |
| 46 | +
|
| 47 | +The above values are the Coder defaults. You will need to change these values in |
| 48 | +accordance with the applied SCC. To get a current list of SCCs, run the below command: |
| 49 | +
|
| 50 | +```console |
| 51 | +oc get scc |
| 52 | +``` |
| 53 | + |
| 54 | +> Note: you must have cluster-admin privileges to manage SCCs |
| 55 | +
|
| 56 | +### 3. Set the `CODER_CACHE_DIRECTORY` environment variable |
| 57 | + |
| 58 | +By default, Coder creates the cache directory in `/home/coder/.cache`. Given the |
| 59 | +OpenShift-provided UID, the Coder container does not have permission to write to |
| 60 | +this directory. |
| 61 | + |
| 62 | +To address this issue, you will need to set the `CODER_CACHE_DIRECTORY` environment |
| 63 | +variable in your Helm values to the following: |
| 64 | + |
| 65 | +```yaml |
| 66 | +coder: |
| 67 | + env: |
| 68 | + - name: CODER_CACHE_DIRECTORY |
| 69 | + value: /tmp/coder-cache |
| 70 | +``` |
| 71 | +
|
| 72 | +### 4. Set access URL, PostgreSQL connection values |
| 73 | +
|
| 74 | +Set the `CODER_PG_CONNECTION_URL` value to enable Coder to establish a connection |
| 75 | +to a PostgreSQL instance. [See our Helm documentation](./kubernetes.md) on configuring |
| 76 | +the PostgreSQL connection URL as a secret. Additionally, if accessing Coder over a hostname, set |
| 77 | +the `CODER_ACCESS_URL` value. |
| 78 | + |
| 79 | +```yaml |
| 80 | +coder: |
| 81 | + env: |
| 82 | + - name: CODER_PG_CONNECTION_URL |
| 83 | + valueFrom: |
| 84 | + secretKeyRef: |
| 85 | + key: url |
| 86 | + name: coder-db-url |
| 87 | + - name: CODER_ACCESS_URL |
| 88 | + value: 'https://coder-example.apps.openshiftapps.com' |
| 89 | +``` |
| 90 | + |
| 91 | +### 5. Configure the Coder service |
| 92 | + |
| 93 | +In this step, we will configure the Coder service as a `ClusterIP`, and create an |
| 94 | +OpenShift route that points to the service HTTP target port. |
| 95 | + |
| 96 | +> Note that setting the `ClusterIP` service type for Coder is not required. |
| 97 | +> `LoadBalancer` and `NodePort` services types can be used. |
| 98 | + |
| 99 | +Below are the Helm chart values for configuring the Coder service as a `ClusterIP`: |
| 100 | + |
| 101 | +```yaml |
| 102 | +coder: |
| 103 | + service: |
| 104 | + type: ClusterIP |
| 105 | +``` |
| 106 | + |
| 107 | +Below is the YAML spec for creating an OpenShift route that sends traffic to the |
| 108 | +HTTP port of the Coder service: |
| 109 | + |
| 110 | +```yaml |
| 111 | +kind: Route |
| 112 | +apiVersion: route.openshift.io/v1 |
| 113 | +metadata: |
| 114 | + namespace: coder |
| 115 | +spec: |
| 116 | + host: https://coder-example.apps.openshiftapps.com |
| 117 | + to: |
| 118 | + kind: Service |
| 119 | + name: coder |
| 120 | + tls: |
| 121 | + # if set to edge, OpenShift will terminate TLS prior to the traffic reaching |
| 122 | + # the service. |
| 123 | + termination: edge |
| 124 | + # if set to Redirect, insecure client connections are redirected to the secure |
| 125 | + # port |
| 126 | + insecureEdgeTerminationPolicy: Redirect |
| 127 | + port: |
| 128 | + targetPort: http |
| 129 | +``` |
| 130 | + |
| 131 | +Once complete, you can create this route in OpenShift via: |
| 132 | + |
| 133 | +```console |
| 134 | +oc apply -f route.yaml |
| 135 | +``` |
| 136 | + |
| 137 | +### 6. Install Coder |
| 138 | + |
| 139 | +You can now install Coder using the values you've set from the above steps. To do |
| 140 | +so, run the series of `helm` commands below: |
| 141 | + |
| 142 | +```console |
| 143 | +helm repo add coder-v2 https://helm.coder.com/v2 |
| 144 | +helm repo update |
| 145 | +helm install coder coder-v2/coder \ |
| 146 | + --namespace coder \ |
| 147 | + --values values.yaml |
| 148 | +``` |
0 commit comments