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:
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
service-deployment-848c68b85-m62qb 1/1 Running 0 90m 10.244.1.45 node2
service-deployment-848c68b85-qwz5w 1/1 Running 0 90m 10.244.2.46 node3
在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
修改配置,kube-flannel-ds为flannel配置文件名称
kubectl edit daemonset kube-flannel-ds -n kube-system
找到所有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
删除之后,重新创建即可正常访问