Planning to run Istio locally?¶
Changes to enable Istio locally¶
-
Update the ./deployment/helm/values-local.yaml file
a) New Variables:
-
localDev:
This variable will tell Helm when we are on our machine vs going through the pipeline. -
localRoute:
This variable will supply a source and destination route for Istio mapping. In the example code below, you’ll see/myapp/
, replacemyapp
with whatever you would like.
b) Existing Variables:
-
green.enabled:
&blue.enabled:
Setting these to true will enable Blue/Green deployments locally -
gateway.enabled:
Setting this to true will tell helm to setup a gateway and use Istio for routing to our application
Example
localDev: true localRoute: source: /myapp/ destination: / ... green: enabled: true blue: enabled: true ... gateway: enabled: true
-
-
Open up your
ingress-secrets.tpl
and add a new if statement around the entire contents checking for thelocalDev
variableExample
{{ if not (default .Values.localDev false) }} ... {{ end }}
-
The last file we need to change is your
virtualservice.yaml
. Istio will route all applications through the root oflocalhost
, so if we have more than one application, we need to have Istio listen for those applications athttp://localhost/myapp/
instead and internally route them to/
for ourapi/website
. You should see the following code block in yourvirtualservice.yaml
:Example
{{ if and .Values.blue.enabled .Values.green.enabled }} - name: test match: - headers: {{ .Values.virtualService.headerName }}: exact: {{ .Values.virtualService.headerValue }} rewrite: uri: / route: - destination: port: number: 80 host: {{ include "[project_name].fullname" . }} subset: test {{ end }}
We need to swap that for this:
Example
{{ if and .Values.blue.enabled .Values.green.enabled }} {{ if not (default .Values.localDev false) }} - name: test match: - headers: {{ .Values.virtualService.headerName }}: exact: {{ .Values.virtualService.headerValue }} rewrite: uri: / route: - destination: port: number: 80 host: {{ include [project_name].fullname" . }} subset: test {{ else }} - name: test match: - uri: prefix: {{ .Values.localRoute.source }} rewrite: uri: {{ .Values.localRoute.destination }} route: - destination: port: number: 80 host: {{ include "[project_name].fullname" . }} subset: test {{ end }} {{ end }}
This new if
statement is only triggered when localDev
is set to true. Here we are adding in a uri prefix for Istio to match against and then supplying a rewrite which tells Istio what to rewrite that match to. For example, if I had /myapp/
as my .Values.localRoute.source
and /
as my .Values.localRoute.destination
, when I go to http://localhost/myapp/
, Istio would translate that into localhost/
for our app/website
.
Be sure to replace [project_name] (including the []) with the name of your project.