I hope you’re all doing well. I’m currently working on a deployment setup in Nomad and I’m facing a challenge related to configuring service tags for Nginx.
How to Add Service Tags to Nginx for Pre-Deployment Application Routing?
I have successfully deployed an Nginx job along with another application job in Nomad. The Nginx job is configured to proxy requests to the application job. When updating the application image and redeploying, I’m adopting a canary deployment strategy.
During this canary deployment phase, I would like to attach specific service tags to the Nginx job. The goal is to ensure that Nginx routes traffic only to the existing version of the application, prior to the full deployment.
Despite attempting to configure this in a way similar to Consul, I haven’t achieved the desired outcome.
If anyone in the community has insights or guidance on how to add service tags to Nginx in this specific scenario, I would greatly appreciate your assistance!
Why do you want to attach service tags to Nginx and not to the deployed application? I do not understand that part
So the simplest way is to use fabio or traefik. They both use service tags attached to the application to discover them and forward. If they discover two applications with same service tags (like during canary deployment) it is also handled.
# Find interesting services and store them in a map.
{{- range $service := services }}
{{- range $tag := $service.Tags }}
{{- if eq (printf "%.10s" $tag) "urlprefix-" }}
{{- scratch.MapSet "services" $service.Name $service.Name }}
{{- end }}
{{- end }}
{{- end }}
# Each service generates an upstream
{{- range (scratch.MapValues "services") }}
upstream {{.}} {
{{- range service . }}
server {{.Address}}:{{.Port}};
{{- end }}
}
{{- end }}
server {
listen 80:
# Generate locations.
{{- range (scratch.MapValues "services") }}
location {{.}}/ {
backend {{.}};
}
{{- end }}
}
The code above is basically the functionality of fabio and traefik, so I recommend to rather use them.