共计 2267 个字符,预计需要花费 6 分钟才能阅读完成。
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: <none>
Annotations: <none>
Selector: app=nginx-pod
Type: ClusterIP
IP Families: <none>
IP: 10.1.97.97
IPs: 10.1.97.97
Port: <unset> 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: <none>
pod 信息
[root@node1 ~]# kubectl get pod -n dev -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
service-deployment-848c68b85-8jvcv 1/1 Running 0 90m 10.244.1.44 node2 <none> <none>
service-deployment-848c68b85-m62qb 1/1 Running 0 90m 10.244.1.45 node2 <none> <none>
service-deployment-848c68b85-qwz5w 1/1 Running 0 90m 10.244.2.46 node3 <none> <none>
在 node2 节点上拜访 node3 上的 pod 10.244.2.46:80 不通
2. 解决过程
找到 flannel 配置名
[root@node2 docker]# kubectl get pod -n kube-system
NAME READY STATUS RESTARTS AGE
coredns-7f89b7bc75-jvfhw 1/1 Running 4 6d12h
coredns-7f89b7bc75-x6kqb 1/1 Running 4 6d12h
etcd-node1 1/1 Running 4 6d12h
kube-apiserver-node1 1/1 Running 4 6d12h
kube-controller-manager-node1 1/1 Running 8 6d12h
--
kube-flannel-ds-bqs55 1/1 Running 0 18h
kube-flannel-ds-czjxv 1/1 Running 5 6d12h
kube-flannel-ds-mbgm4 1/1 Running 4 6d12h
---
kube-proxy-2tn4g 1/1 Running 0 132m
kube-proxy-4tc4f 1/1 Running 0 132m
kube-proxy-bwsgv 1/1 Running 0 132m
kube-scheduler-node1 1/1 Running 8 6d12h
获取 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-b7qfq 1/1 Running 0 29s
kube-flannel-ds-w9hts 1/1 Running 0 17s
kube-flannel-ds-zpzmb 0/1 Init:0/1 0 1s
[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…
正文完