我有一个带有(kubernetes(Nginx Ingress 控制器的 Kubernetes 集群,具有以下入口规则:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: ingress-rules
# namespace: default
### Virtual hosts ###
spec:
rules:
- host: dashboard.example.com
http:
paths:
- path: /
backend:
serviceName: test
servicePort: 443
test
应用程序由 Tomcat 服务器提供服务。
雄猫的server.xml
是:
<?xml version="1.0" encoding="UTF-8"?>
<Server port="8005" shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.startup.VersionLoggerListener" />
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
<Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" />
<GlobalNamingResources>
<Resource name="UserDatabase" auth="Container"
type="org.apache.catalina.UserDatabase"
description="User database that can be updated and saved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml" />
</GlobalNamingResources>
<Service name="Catalina">
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
URIEncoding="UTF-8"
redirectPort="443" />
<Connector port="443" protocol="org.apache.coyote.http11.Http11NioProtocol"
sslImplementationName="org.apache.tomcat.util.net.jsse.JSSEImplementation"
scheme="https" secure="true" URIEncoding="UTF-8"
maxThreads="150" SSLEnabled="true">
<SSLHostConfig>
<Certificate certificateKeystoreFile="conf/odvsdva.p12"
certificateKeystorePassword="sdvsdvsdvsd"
type="RSA" />
</SSLHostConfig>
</Connector>
<Connector port="8009" protocol="AJP/1.3" redirectPort="443" />
<Engine name="Catalina" defaultHost="localhost">
<Realm className="org.apache.catalina.realm.LockOutRealm">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
</Realm>
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log" suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
</Engine>
</Service>
</Server>
当我在浏览器中打开时dashboard.example.com
当Ingress
中的路径/
时,我得到 Tomcat 标准状态页面(如果您看到此消息,则表示您已成功安装 Tomcat。恭喜!
现在,如果我转到dasboard.example.com/test
我可以打开我的应用程序。
但是,我想通过导航到dashboard.example.com/
来打开该应用程序。
因此,我尝试将Ingress
中的路径从/test
中的/
更改为。但是后来我在浏览器中得到了This site can’t be reached
。
我没有设置Tomcat,我对它的专业知识很少。我希望我在上面提供足够的细节。
编辑
我的 k8s 集群位于 Ubuntu vagrant VM 中。
root@vagrant:/home/vagrant# kubectl version
Client Version: version.Info{Major:"1", Minor:"15", GitVersion:"v1.15.4", GitCommit:"67d2fcf276fcd9cf743ad4be9a9ef5828adc082f", GitTreeState:"clean", BuildDate:"2019-09-18T14:51:13Z", GoVersion:"go1.12.9", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"15", GitVersion:"v1.15.7", GitCommit:"6c143d35bb11d74970e7bc0b6c45b6bfdffc0bd4", GitTreeState:"clean", BuildDate:"2019-12-11T12:34:17Z", GoVersion:"go1.12.12", Compiler:"gc", Platform:"linux/amd64"}
将入口中的路径保留为/
从 tomcat 中删除现成的ROOT/
目录,并在部署之前将 war 文件重命名为ROOT.war
。
我相信您正在寻找的东西是nginx.ingress.kubernetes.io/rewrite-target
,而是为了插入路径组件而不是像他们的例子那样删除它:
kind: Ingress
metadata:
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /test$1
spec:
rules:
- host: dashboard.example.com
http:
paths:
- path: '(/.*)'