K8s中Service IP无法访问Pod问题求助(SpringBoot应用场景)
K8s单节点集群SpringBoot应用访问失败排查请求
集群环境信息
[root@devops1722021165 k8s]# kubectl version Client Version: version.Info{Major:"1", Minor:"17", GitVersion:"v1.17.3", GitCommit:"06ad960bfd03b39c8310aaf92d1e7c12ce618213", GitTreeState:"clean", BuildDate:"2020-02-11T18:14:22Z", GoVersion:"go1.13.6", Compiler:"gc", Platform:"linux/amd64"} Server Version: version.Info{Major:"1", Minor:"17", GitVersion:"v1.17.17", GitCommit:"f3abc15296f3a3f54e4ee42e830c61047b13895f", GitTreeState:"clean", BuildDate:"2021-01-13T13:13:00Z", GoVersion:"go1.13.15", Compiler:"gc", Platform:"linux/amd64"} [root@devops1722021165 k8s]# kubectl get nodes NAME STATUS ROLES AGE VERSION devops1722021165 Ready master 23d v1.17.3
SpringBoot应用代码
/** * @author zhengtao on 2023/12/2 */ @RestController public class TestController { @RequestMapping("/hello") public String helloWorld() { return "hello world"; } }
部署配置文件
Deployment配置(docker-study-deployment.yaml)
apiVersion: apps/v1 kind: Deployment metadata: name: docker-study-deployment spec: selector: matchLabels: app: docker-study-deployment replicas: 2 strategy: type: RollingUpdate rollingUpdate: maxSurge: 1 maxUnavailable: 1 template: metadata: labels: app: docker-study-deployment spec: containers: - name: docker-study image: wzgl998877/docker-study ports: - containerPort: 80
Service配置(docker-study-svc.yaml)
apiVersion: v1 kind: Service metadata: name: docker-study-svc spec: selector: app: docker-study-deployment ports: - port: 80 targetPort: 8080 protocol: TCP type: NodePort
问题现象
已执行kubectl apply -f docker-study-deployment.yaml完成部署,执行kubectl apply -f docker-study-svc.yaml创建Service,确认deployment和service均处于运行状态。但:
- 执行
curl http://10.97.154.229:30577/hello无响应 - 进入Pod内执行
curl http://10.97.154.229:8080/hello,返回curl: (7) Failed to connect to 10.97.154.229 port 8080: Connection refused
恳请协助解决该问题,谢谢!
内容的提问来源于stack exchange,提问作者tao zheng
相关产品推荐
相关产品推荐

