[英]Container docker & Kubernetes apache tomcat 8.5.56 http status 404
請我在 docker 容器中的 apache tomcat 8.5.56 上運行 .war 應用程序並且一切正常,但是當我在 Kubernetes 上創建部署容器時,我可以訪問我的應用程序歡迎頁面:我有錯誤消息
HTTP Status 404 – Not Found
Type Status Report
Message The requested resource [/SmartClass] is not available
Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.
Apache Tomcat/8.5.56
請問有人知道怎么解決嗎?
對於部署,我剛剛將 .war 文件復制到/opt/apache-tomcat/webapps/
並將我的 server.xml 文件復制到/opt/apache-tomcat/conf/
看起來問題與應用程序的連接有關。
創建一個暴露 Tomcat 部署的服務對象:
kubectl expose deployment tomcat-example --type=NodePort --name=example-service
顯示有關服務的信息:
kubectl describe services example-service
輸出類似於:
Name: example-service Namespace: default Labels: run=lexample Annotations: <none> Selector: run=example Type: NodePort IP: 10.32.0.16 Port: <unset> 8080/TCP TargetPort: 8080/TCP NodePort: <unset> 30000/TCP Endpoints: 10.200.1.4:8080,10.200.2.5:8080 Session Affinity: None Events: <none>
記下服務的 NodePort 值。 例如,在前面的輸出中,NodePort 值為 30000。
列出正在運行 Tomcat 應用程序的 pod:
kubectl get pods --selector="run=example" --output=wide
輸出類似於:
NAME READY STATUS ... IP NODE tomcat-2895499144-bsbk5 1/1 Running ... 10.200.1.4 worker1 tomcat-2895499144-m1pwt 1/1 Running ... 10.200.2.5 worker2
獲取運行 Tomcat pod 的節點之一的公共 IP 地址。 您如何獲得此地址取決於您如何設置集群。 例如,如果您使用 Minikube,則可以通過運行kubectl cluster-info
來查看節點地址。 如果您使用的是 Google Compute Engine 實例,則可以使用gcloud compute instances list
命令查看節點的公共地址。
在您選擇的節點上,創建一個防火牆規則,允許您的節點端口上的 TCP 流量。 例如,如果您的服務的 NodePort 值為 31568,則創建一個防火牆規則,允許端口 30000 上的 TCP 流量。不同的雲提供商提供不同的配置防火牆規則的方法。
使用節點地址和節點端口訪問Hello World應用程序:
curl http://<public-node-ip>:<node-port>
其中<public-node-ip>
是您節點的公共 IP 地址, <node-port>
是您的服務的 NodePort 值。 請根據您使用的正確名稱和值調整上述命令。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.