简体   繁体   中英

Kubernetes env referencing a pod/service

I have been trying to port over some infrastructure to K8S from a VM docker setup.

In a traditional VM docker setup I run 2 docker containers: 1 being a proxy node service, and another utilizing the proxy container through an .env file via: docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' proxy-container

172.17.0.2

Then within the .env file: URL=ws://172.17.0.2:4000/

This is what I am trying to setup within a cluster in K8S but failing to reference the proxy-service correctly. I have tried using the proxy-service pod name and/or the service name with no luck.

My env-configmap.yaml is:

apiVersion: v1
kind: ConfigMap
metadata:
  name: env-config
data:
  URL: "ws://$(proxy-service):4000/"

Containers that run in the same pod can connect to each other via localhost . Try URL: "ws://localhost:4000/" in your ConfigMap. Otherwise, you need to specify the service name like URL: "ws://proxy-service.<namespace>:4000" .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM