You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Unit]Description="Frontend service"# The service requires the VM's network# to be configured, e.g., an IP address has been assigned.Requires=network-online.target
After=network-online.target
[Service]# ExecStart is the command to run.ExecStart=/usr/local/bin/frontend
# Restart configures the restart policy. In this case, we# want to restart the service if it fails.Restart=on-failure
# Environment sets environment variables.# We will set the frontend service to listen# on port 6060.Environment=BIND_ADDR=0.0.0.0:6060
# We set BACKEND_URL to http://localhost:7000 because# that's the port we'll run our backend service on.Environment=BACKEND_URL=http://localhost:7000
# The Install section configures this service to start# automatically if the VM reboots.[Install]WantedBy=multi-user.target
Example 4-6: backend.service
[Unit]Description="Backend service"Requires=network-online.target
After=network-online.target
[Service]ExecStart=/usr/local/bin/backend
Restart=on-failure
# We will set the backend service to listen# on port 7000.Environment=BIND_ADDR=0.0.0.0:7000
[Install]WantedBy=multi-user.target
Example 4-7: frontend.hcl
service {
name="frontend"# frontend runs on port 6060.port=6060# The "connect" stanza configures service mesh# features.connect {
sidecar_service {
# frontend's proxy will listen on port 21000.port=21000proxy {
# The "upstreams" stanza configures# which ports the sidecar proxy will expose# and what services they'll route to.upstreams=[
{
# Here you're configuring the sidecar proxy to# proxy port 6001 to the backend service.
destination_name ="backend"
local_bind_port =6001
}
]
}
}
}
}
Example 4-8: backend.hcl
service {
name="backend"# backend runs on port 7000.port=7000meta {
version="v1"
}
# The backend service doesn't call# any other services so it doesn't# need an "upstreams" stanza.## The connect stanza is still required to# indicate that it needs a sidecar proxy.connect {
sidecar_service {
# backend's proxy will listen on port 22000.port=22000
}
}
}