我确实有一个容器,它运行映像并在特定的路径和端口上公开应用程序(例如localhost:8080/app_a)。
在K8s中,我设置了这样一个服务:
apiVersion: v1
kind: Service
...
spec:
selector:
application: "{{{APPLICATION}}}"
component: "{{{COMPONENT}}}"
environment: "{{{ENVIRONMENT}}}"
type: ClusterIP
ports:
- protocol: TCP
targetPort: 8080
port: 80
name: http
并且入口如下:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: "{{{COMPONENT}}}"
namespace: "{{{NAMESPACE}}}"
labels:
application: "{{{APPLICATION}}}"
component: "{{{COMPONENT}}}"
environment: "{{{ENVIRONMENT}}}"
spec:
rules:
- host: "{{{COMPONENT}}}.{{{TARGET_K8S}}}.company.domain"
http:
paths:
- backend:
serviceName: "{{{COMPONENT}}}"
servicePort: 80
path: /app_A
pathType: ImplementationSpecific
通过以上设置,我可以通过以下入口端点访问所需路径:
{{}组件}}。{{{TARGET_K8S}}}.company.domain/app_A
是否可以在Service组件中以某种方式映射targetPath,以便它直接从容器中公开端点localhost:8080/app_A?这样,当我想访问这个应用程序时,就不需要在ingress端点中添加app_A。
你能尝试以下操作吗
- backend:
serviceName: "{{{COMPONENT}}}"
servicePort: 80
path: /app_A
pathType: ImplementationSpecific