欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Kubernetes访问报错: No route to host

程序员文章站 2024-03-13 23:53:04
...

背景

搭建完集群式k8s后,各个节点都已经Ready,但是在创建echo服务进行访问时报错:No route to host

解决

参考链接:https://imlc.me/v/zh-cn/kuai-su-jie-jue-kubernetes-no-route-to-host

(一)集群式部署

[[email protected] kong]# systemctl stop kubelet
[[email protected] kong]# systemctl stop docker
[[email protected] kong]# iptables --flush
[[email protected] kong]# iptables -tnat --flush
[[email protected] kong]# systemctl start kubelet
[[email protected] kong]# systemctl start docker

(二)Microk8s部署

[[email protected] kong]# microk8s stop
[[email protected] kong]# systemctl stop docker
[[email protected] kong]# iptables --flush
[[email protected] kong]# iptables -tnat --flush
[[email protected] kong]# systemctl start docker
[[email protected] kong]# microk8s start

测试

[[email protected] kong]# kubectl get svc -n demo -o wide
NAME   TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)           AGE   SELECTOR
echo   ClusterIP   10.105.104.233   <none>        8080/TCP,80/TCP   26m   app=echo
[[email protected] kong]# curl http://10.105.104.233


Hostname: echo-8467949b65-mt4vk

Pod Information:
        node name:      k8s-worker-1
        pod name:       echo-8467949b65-mt4vk
        pod namespace:  demo
        pod IP: 10.36.0.0

Server values:
        server_version=nginx: 1.13.3 - lua: 10008

Request Information:
        client_address=10.32.0.1
        method=GET
        real path=/
        query=
        request_version=1.1
        request_scheme=http
        request_uri=http://10.105.104.233:8080/

Request Headers:
        accept=*/*
        host=10.105.104.233
        user-agent=curl/7.29.0

Request Body:
        -no body in request-