简体   繁体   English

在 Kubernetes 中获取 URL 名称

[英]GET URL Name in Kubernetes

I use spring boot project and deployed in Kubernetes, I would like to get URL of the pod,我使用 spring boot 项目并部署在 Kubernetes 中,我想获取 pod 的 URL,

I referred How to Get Current Pod in Kubernetes Java Application not worked for me.我提到了如何在 Kubernetes Java 应用程序中获取当前 Pod对我不起作用

There are different environments (DEV, QA, etc..) and wanted to get URL dynamically, is there anyway?有不同的环境(DEV、QA 等)并且想要动态获取 URL,是吗?

my service yaml我的服务 yaml

apiVersion: serving.knative.dev/v1alpha1
kind: Service
metadata:
  name: test-service
  namespace: default
spec:
  template:
    metadata:
      annotations:
        autoscaling.knative.dev/metric: concurrency
        # Disable scale to zero with a minScale of 1.
        autoscaling.knative.dev/minScale: "1"
        # Limit scaling to 100 pods.
        autoscaling.knative.dev/maxScale: "100"
    spec:
      containers:
        - image: testImage
          ports:
            - containerPort: 8080

is it possible to add是否可以添加

valueFrom:
     fieldRef:
     fieldPath: status.podIP

from url https://kubernetes.io/docs/tasks/inject-data-application/environment-variable-expose-pod-information/#the-downward-api来自 url https://kubernetes.io/docs/tasks/inject-data-application/environment-variable-expose-pod-information/#the-downward-api

Your case is about Knative ingress, and not Kubernetes.您的案例是关于 Knative 入口,而不是 Kubernetes。

From the inbound network connectivity part of the runtime contract of the knative documentation :knative 文档运行时合同的入站网络连接部分:

In addition, the following base set of HTTP/1.1 headers MUST be set on the request:此外,必须在请求上设置以下基本的 HTTP/1.1 标头集:

  • Host - As specified by RFC 7230 Section 5.4主机 - 由 RFC 7230 第 5.4 节指定

Also, the following proxy-specific request headers MUST be set:此外,必须设置以下特定于代理的请求标头:

  • Forwarded - As specified by RFC 7239.转发 - 按照 RFC 7239 的规定。

Look to the headers inside your request.查看请求中的标头。

An example for servlet doGet method: servlet doGet方法的示例:

Enumeration<String> headerNames = request.getHeaderNames();
while(headerNames.hasMoreElements()) {
  String paramName = (String)headerNames.nextElement();
  out.print("<tr><td>" + paramName + "</td>\n");
  String paramValue = request.getHeader(paramName);
  out.println("<td> " + paramValue + "</td></tr>\n");
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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