diff --git a/kubernetes-manifests/productcatalogservice.yaml b/kubernetes-manifests/productcatalogservice.yaml index 9161a54..34a5628 100644 --- a/kubernetes-manifests/productcatalogservice.yaml +++ b/kubernetes-manifests/productcatalogservice.yaml @@ -31,6 +31,9 @@ spec: image: productcatalogservice ports: - containerPort: 3550 + env: + - name: PORT + value: "3550" readinessProbe: exec: command: ["/bin/grpc_health_probe", "-addr=:3550"] diff --git a/src/productcatalogservice/server.go b/src/productcatalogservice/server.go index c55e0af..60b0f3a 100644 --- a/src/productcatalogservice/server.go +++ b/src/productcatalogservice/server.go @@ -50,7 +50,7 @@ var ( log *logrus.Logger extraLatency time.Duration - port = flag.Int("port", 3550, "port to listen at") + port = "3550" reloadCatalog bool ) @@ -106,13 +106,16 @@ func main() { } }() - log.Infof("starting grpc server at :%d", *port) - run(*port) + if os.Getenv("PORT") != "" { + port = os.Getenv("PORT") + } + log.Infof("starting grpc server at :%s", port) + run(port) select {} } -func run(port int) string { - l, err := net.Listen("tcp", fmt.Sprintf(":%d", port)) +func run(port string) string { + l, err := net.Listen("tcp", fmt.Sprintf(":%s", port)) if err != nil { log.Fatal(err) }