[英]k8s master node cannot access the pod or service through virtual ip
the master node cannot access service or pod through virtual ip ,Network plugins flannel work just fine.主节点无法通过虚拟 ip 访问服务或 pod,网络插件法兰绒工作得很好。
[root@www ~]# clear
[root@www ~]# kubectl get pod --all-namespaces -o wide
NAMESPACE NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
default java-demo-c7765d5cd-kfglv 1/1 Running 1 3h48m 10.244.1.13 www.server03.com <none> <none>
default java-demo-c7765d5cd-pcdjk 1/1 Running 1 3h48m 10.244.0.12 www.server02.com <none> <none>
kube-system coredns-68d7b6f657-mn7fx 1/1 Running 1 6d17h 10.244.1.14 www.server03.com <none> <none>
kube-system kube-flannel-ds-amd64-f8hd2 1/1 Running 3 6d19h 192.168.254.5 www.server02.com <none> <none>
kube-system kube-flannel-ds-amd64-h9xsq 1/1 Running 2 6d19h 192.168.254.6 www.server03.com <none> <none>
[root@www ~]# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
java-demo NodePort 10.0.0.153 <none> 80:30018/TCP 3h18m
kubernetes ClusterIP 10.0.0.1 <none> 443/TCP 6d23h
[root@www ~]# curl 10.0.0.153
curl: (7) Failed connect to 10.0.0.153:80; 拒绝连接
[root@www ~]# curl 10.244.1.14:8080
curl: (7) Failed connect to 10.244.1.14:8080; 拒绝连接
[root@www ~]# ping 10.0.0.153
PING 10.0.0.153 (10.0.0.153) 56(84) bytes of data.
--- 10.0.0.153 ping statistics ---
119 packets transmitted, 0 received, 100% packet loss, time 118011ms
the node can access the service virtual ip,execute instructions on the node as follows:节点可以访问服务虚拟ip,在节点上执行指令如下:
[root@www ~]# clear
[root@www ~]# ping 10.0.0.153
PING 10.0.0.153 (10.0.0.153) 56(84) bytes of data.
64 bytes from 10.0.0.153: icmp_seq=1 ttl=64 time=0.124 ms
64 bytes from 10.0.0.153: icmp_seq=2 ttl=64 time=0.040 ms
64 bytes from 10.0.0.153: icmp_seq=3 ttl=64 time=0.038 ms
64 bytes from 10.0.0.153: icmp_seq=4 ttl=64 time=0.072 ms
64 bytes from 10.0.0.153: icmp_seq=5 ttl=64 time=0.039 ms
^C
--- 10.0.0.153 ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4000ms
rtt min/avg/max/mdev = 0.038/0.062/0.124/0.034 ms
[root@www ~]#
the java-demo.yaml java-demo.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: java-demo
name: java-demo
spec:
replicas: 2
selector:
matchLabels:
app: java-demo
template:
metadata:
labels:
app: java-demo
spec:
containers:
- image: java-demo:v1
name: java-demo
the service.yaml服务.yaml
apiVersion: v1
kind: Service
metadata:
labels:
app: java-demo
name: java-demo
spec:
ports:
- port: 80
protocol: TCP
targetPort: 8080
nodePort: 30018
selector:
app: java-demo
type: NodePort
This service can be accessed normally on the node after exposure and the pod container is just not accessible virtual IP on the master node.该服务暴露后可以在节点上正常访问,而pod容器只是主节点上无法访问的虚拟IP。 Please help me, thank you!
请帮帮我,谢谢!
You are using NodePort
type to expose the Deployment
, your service will not be accessible via your virtual IP.您正在使用
NodePort
类型来公开Deployment
,您的服务将无法通过您的虚拟 IP 访问。
Inside Kubernetes docs we can read:在 Kubernetes 文档中,我们可以阅读:
For some parts of your application (for example, frontends) you may want to expose a Service onto an external IP address, that's outside of your cluster.
对于应用程序的某些部分(例如,前端),您可能希望将服务公开到集群之外的外部 IP 地址上。
Kubernetes
ServiceTypes
allow you to specify what kind of Service you want.Kubernetes
ServiceTypes
允许您指定所需的服务类型。 The default isClusterIP
.默认值为
ClusterIP
。
Type
values and their behaviors are:Type
值及其行为是:
ClusterIP
: Exposes the Service on a cluster-internal IP.ClusterIP
:在集群内部 IP 上公开服务。 Choosing this value makes the Service only reachable from within the cluster.选择此值会使服务只能从集群内部访问。 This is the default
ServiceType
.这是默认的
ServiceType
。NodePort
: Exposes the Service on each Node's IP at a static port (theNodePort
).NodePort
:在静态端口(NodePort
)的每个节点的 IP 上公开服务。 AClusterIP
Service, to which theNodePort
Service routes, is automatically created.NodePort
服务路由到的ClusterIP
服务会自动创建。 You'll be able to contact theNodePort
Service, from outside the cluster, by requesting<NodeIP>:<NodePort>
.您将能够通过请求
<NodeIP>:<NodePort>
从集群外部联系NodePort
服务。LoadBalancer
: Exposes the Service externally using a cloud provider's load balancer.LoadBalancer
:使用云提供商的负载均衡器在外部公开服务。NodePort
andClusterIP
Services, to which the external load balancer routes, are automatically created.外部负载均衡器路由到的
NodePort
和ClusterIP
服务是自动创建的。ExternalName
: Maps the Service to the contents of theexternalName
field (egfoo.bar.example.com
), by returning aCNAME
record with its value.ExternalName
:通过返回带有其值的CNAME
记录,将服务映射到externalName
字段(例如foo.bar.example.com
)的内容。 No proxying of any kind is set up.没有设置任何类型的代理。
Also your Deployemnt
is missing containerPort
.此外,您的
Deployemnt
缺少containerPort
。 Here is a link to docs how to Create a Deployment .这是文档的链接如何创建部署。
Please also consider reading Connecting Applications with Services as it's providing examples of different types.还请考虑阅读连接应用程序与服务,因为它提供了不同类型的示例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.