[英]how to use service name inside kubernetes pod
i want to replace this two value ( . . .*** = @IP) enter image description here我想替换这两个值 ( . . . .*** = @IP) enter image description here
with service name enter image description here使用服务名称在此处输入图像描述
Any solution plz?有什么解决办法吗?
For example, let's say your service spec looks like this:例如,假设您的服务规范如下所示:
apiVersion: v1
kind: Service
metadata:
name: api
namespace: einstore # <-- you need to specify the namespace
labels:
app: api
spec:
type: NodePort
ports:
- port: 8080
nodePort: 30001
targetPort: 8080
protocol: TCP
name: api
selector:
app: api
Similarly for your deployment:同样对于您的部署:
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: api
name: api
namespace: einstore # <-- you need to specify the namespace
spec:
selector:
...
Within the cluster (eg. pod to pod), you can refer to the service as:在集群中(例如 pod 到 pod),您可以将服务称为:
- name: APICORE_SERVER_URL
value: "http://api.einstore:8080"
this is my service his name is api这是我的服务 他的名字是 api
apiVersion: v1
kind: Service
metadata:
name: api
labels:
app: api
spec:
type: NodePort
ports:
- port: 8080
nodePort: 30001
targetPort: 8080
protocol: TCP
name: api
selector:
app: api
and this is my deployement这是我的部署
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: api
name: api
spec:
selector:
matchLabels:
app: api
template:
metadata:
labels:
app: api
spec:
containers:
- name: api
image: einstore/einstore-core:0.1.1
env:
- name: APICORE_STORAGE_LOCAL_ROOT
value: "/home/einstore"
- name: APICORE_SERVER_NAME
value: "Einstore - Enterprise AppStore"
- name: APICORE_SERVER_MAX_UPLOAD_FILESIZE
value: "50"
- name: APICORE_DATABASE_HOST
value: "postgres"
- name: APICORE_DATABASE_USER
value: "einstore"
- name: APICORE_DATABASE_PASSWORD
value: "einstore"
- name: APICORE_DATABASE_DATABASE
value: "einstore"
- name: APICORE_DATABASE_PORT
value: "5432"
- name: APICORE_DATABASE_LOGGING
value: "false"
- name: APICORE_JWT_SECRET
value: "secret"
- name: APICORE_STORAGE_S3_ENABLED
value: "false"
- name: APICORE_STORAGE_S3_BUCKET
value: "~"
- name: APICORE_STORAGE_S3_ACCESS_KEY
value: "~"
- name: APICORE_STORAGE_S3_REGION
value: "~"
- name: APICORE_STORAGE_S3_SECRET_KEY
value: "~"
- name: APICORE_SERVER_URL
value: "http://**.***.*.***:30001/"
when i try to replace the *** with my machine @ip Everything works,But what I need is to change that so that there is the name of the service so that I can deploy the app in any other machine the first solution LGTM but i get this error当我尝试用我的机器@ip 替换 *** 一切正常,但我需要更改它,以便有服务的名称,以便我可以在任何其他机器上部署应用程序第一个解决方案 LGTM 但是我得到这个错误
curl http://api.einstore:8080/
curl: (6) Could not resolve host: api.einstore
NB: einstore= the name of my namespace注意:einstore=我的命名空间的名称
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.