docker - 容器 docker & Kubernetes apache tomcat 8.5.56 http status 404

标签 docker tomcat kubernetes

请我在 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 的节点之一的公共(public) IP 地址。如何获得此地址取决于您如何设置集群。例如,如果您使用 Minikube,您可以通过运行 kubectl cluster-info 查看节点地址.如果您使用的是 Google Compute Engine 实例,则可以使用 gcloud compute instances list命令以查看节点的公共(public)地址。
  • 在您选择的节点上,创建一个防火墙规则,允许您的节点端口上的 TCP 流量。例如,如果您的 Service 的 NodePort 值为 31568,请创建一个防火墙规则,允许端口 30000 上的 TCP 流量。不同的云提供商提供不同的防火墙规则配置方式。
  • 使用节点地址和节点端口访问 Hello World 应用程序:
    curl http://<public-node-ip>:<node-port>
    
    
    在哪里 <public-node-ip>是您节点的公共(public) IP 地址,<node-port>是您的服务的 NodePort 值。
    请根据您使用的正确名称和值调整上述命令。
  • 关于docker - 容器 docker & Kubernetes apache tomcat 8.5.56 http status 404,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63591728/

    相关文章:

    docker - 在Kubernetes中调度和扩展Pod

    Windows docker 容器无法 ping 主机

    azure - 使用 docker 在 azure ubuntu 虚拟机中安装 minikube

    java - 如何在具有不同应用程序上下文的相同端口下将两个 Web 应用程序部署在同一个 tomcat 下?

    spring - 如何在 spring 应用程序属性中获取正在运行的 tomcat 端口

    Tomcat 7 SSL 与 iOS 9 的兼容性

    docker - 如何使用 docker-compose run 查看日志输出?

    kubernetes - HPA无法在GKE节点自动缩放期间获取CPU指标

    kubernetes - 如何更改 kubernetes 中的默认 kube-scheduler

    amazon-ec2 - 将kubernetes从1.5.5升级到1.5.8或1.7/1.8