k8s service创建之后无法访问集群内本节点的其他pod
1.问题
deploy.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: service-deployment
namespace: dev
spec:
replicas: 3
selector:
matchLabels:
app: nginx-pod
template:
metadata:
labels:
app: nginx-pod
spec:
containers:
- name: nginx
image: nginx
imagePullPolicy: IfNotPresent
ports:
- containerPort: 80
service.yaml
apiVersion: v1
kind: Service
metadata:
name: service-type
namespace: dev
spec:
selector:
app: nginx-pod
clusterIP: 10.1.97.97
type: ClusterIP
ports:
- port: 80 #service端口
targetPort: 80 #pod端口
创建之后信息
[root@node1 ~]# kubectl describe svc -n dev
Name:service-type
Namespace:dev
Labels:
Annotations:
Selector:app=nginx-pod
Type:ClusterIP
IP Families:
IP:10.1.97.97
IPs:10.1.97.97
Port:80/TCP
TargetPort:80/TCP
Endpoints:10.244.1.44:80,10.244.1.45:80,10.244.2.46:80
Session Affinity:None
Events:
【k8s service创建之后无法访问集群内本节点的其他pod】pod信息
[root@node1 ~]# kubectl get pod -n dev -o wide
NAMEREADYSTATUSRESTARTSAGEIPNODENOMINATED NODEREADINESS GATES
service-deployment-848c68b85-8jvcv1/1Running090m10.244.1.44node2
service-deployment-848c68b85-m62qb1/1Running090m10.244.1.45node2
service-deployment-848c68b85-qwz5w1/1Running090m10.244.2.46node3
在node2节点上访问node3上的pod 10.244.2.46:80 不通
文章图片
2.解决过程
找到flannel配置名
[root@node2 docker]# kubectl get pod -n kube-system
NAMEREADYSTATUSRESTARTSAGE
coredns-7f89b7bc75-jvfhw1/1Running46d12h
coredns-7f89b7bc75-x6kqb1/1Running46d12h
etcd-node11/1Running46d12h
kube-apiserver-node11/1Running46d12h
kube-controller-manager-node11/1Running86d12h
--
kube-flannel-ds-bqs551/1Running018h
kube-flannel-ds-czjxv1/1Running56d12h
kube-flannel-ds-mbgm41/1Running46d12h
---
kube-proxy-2tn4g1/1Running0132m
kube-proxy-4tc4f1/1Running0132m
kube-proxy-bwsgv1/1Running0132m
kube-scheduler-node11/1Running86d12h
获取flannel的配置名称
kubectl edit pod -n kube-system kube-flannel-ds-bqs55
找到flannel配置名
文章图片
修改配置,kube-flannel-ds为flannel配置文件名称
kubectl edit daemonset kube-flannel-ds -n kube-system
指定网卡为第二块网卡,可以通过ifconfig来进行查看
文章图片
找到所有kube-flannelpod
[root@node2 docker]# kubectl get pod -n kube-system | grep kube-flan
kube-flannel-ds-b7qfq1/1Running029s
kube-flannel-ds-w9hts1/1Running017s
kube-flannel-ds-zpzmb0/1Init:0/101s
[root@node2 docker]# kubectl delete pod -n kube-system kube-flannel-ds-b7qfq kube-flannel-ds-w9hts kube-flannel-ds-zpzmb
pod "kube-flannel-ds-b7qfq" deleted
pod "kube-flannel-ds-w9hts" deleted
pod "kube-flannel-ds-zpzmb" deleted
删除之后,重新创建即可正常访问
参考 https://www.jianshu.com/p/ed1...
推荐阅读
- django-前后端交互
- IDEA|IDEA 创建工程
- Java|Java spi(service provider interface)
- 创建缔造完美教室,让每一间教室都闪闪发光
- K8S|K8S 生态周报| Istio 即将发布重大安全更新,多个版本受影响
- Servlet原理|Servlet原理 二(Web应用与创建Servlet实例)
- 企业为什么要融资
- 个人日记|K8s中Pod生命周期和重启策略
- k8s|Scheduling Framework 与 Extender对比及详细介绍
- k8s|k8s(六)(配置管理与集群安全机制)