我们想测试 Kubernetes 负载均衡。因此,我们创建了一个运行 6 个容器副本的 2 节点集群。容器运行 apache2 服务器和 php,如果我们浏览 hostname.php,它将打印 pod 名称
集群详情: 172.16.2.92 -- master 和 minion 172.16.2.91 -- minion
RC和服务细节:
前端控制器.json:
{
"kind":"ReplicationController",
"apiVersion":"v1beta3",
"metadata":{
"name":"frontend",
"labels":{
"name":"frontend"
}
},
"spec":{
"replicas":6,
"selector":{
"name":"frontend"
},
"template":{
"metadata":{
"labels":{
"name":"frontend"
}
},
"spec":{
"containers":[
{
"name":"php-hostname",
"image":"naresht/hostname",
"ports":[
{
"containerPort":80,
"protocol":"TCP"
}
]
}
]
}
}
}
}
前端服务.json:
{
"kind":"Service",
"apiVersion":"v1beta3",
"metadata":{
"name":"frontend",
"labels":{
"name":"frontend"
}
},
"spec":{
"createExternalLoadBalancer": true,
"ports": [
{
"port":3000,
"targetPort":80,
"protocol":"TCP"
}
],
"publicIPs": [ "172.16.2.92"],
"selector":{
"name":"frontend"
}
}
}
Pod 详细信息: frontend-01bb8、frontend-svxfl 和 frontend-yki5s 在节点 172.16.2.91 上运行 frontend-65ykz、frontend-c1x0d 和 frontend-y925t 在节点 172.16.2.92 上运行
如果我们浏览 172.16.2.92:3000/hostname.php,它会打印 POD 名称。
问题:
在节点 172.16.2.92 上运行 watch -n1 curl 172.16.2.92:3000/hostname.php 仅给出该 pod(frontend-65ykz、frontend-c1x0d 和 frontend-y925t)。他们没有显示其他节点 172.16.2.91 pod。在节点 172.16.2.91 上运行相同的命令只会提供该 pod。他们没有显示其他节点 172.16.2.92 pod。在集群外运行相同的命令仅显示 172.16.2.92 个 pod。但是,如果我们在任何地方运行,我们希望查看所有 pod,而不是特定节点 pod。
检查以下详细信息以获取更多信息,并在出现任何问题时为您提供帮助
# kubectl 获取节点
NAME LABELS STATUS
172.16.2.91 kubernetes.io/hostname=172.16.2.91 Ready
172.16.2.92 kubernetes.io/hostname=172.16.2.92 Ready
# kubectl 获取 pod
POD IP CONTAINER(S) IMAGE(S) HOST LABELS STATUS CREATED MESSAGE
frontend-01bb8 172.17.0.84 172.16.2.91/172.16.2.91 name=frontend Running About a minute
php-hostname naresht/hostname Running About a minute
frontend-65ykz 10.1.64.79 172.16.2.92/172.16.2.92 name=frontend Running About a minute
php-hostname naresht/hostname Running About a minute
frontend-c1x0d 10.1.64.77 172.16.2.92/172.16.2.92 name=frontend Running About a minute
php-hostname naresht/hostname Running About a minute
frontend-svxfl 172.17.0.82 172.16.2.91/172.16.2.91 name=frontend Running About a minute
php-hostname naresht/hostname Running About a minute
frontend-y925t 10.1.64.78 172.16.2.92/172.16.2.92 name=frontend Running About a minute
php-hostname naresht/hostname Running About a minute
frontend-yki5s 172.17.0.83 172.16.2.91/172.16.2.91 name=frontend Running About a minute
php-hostname naresht/hostname Running About a minute
kube-dns-sbgma 10.1.64.11 172.16.2.92/172.16.2.92 k8s-app=kube-dns,kubernetes.io/cluster-service=true,name=kube-dns Running 45 hours
kube2sky gcr.io/google_containers/kube2sky:1.1 Running 45 hours
etcd quay.io/coreos/etcd:v2.0.3 Running 45 hours
skydns gcr.io/google_containers/skydns:2015-03-11-001 Running 45 hours
# kubectl 获取服务
NAME LABELS SELECTOR IP(S) PORT(S)
frontend name=frontend name=frontend 192.168.3.184 3000/TCP
kube-dns k8s-app=kube-dns,kubernetes.io/cluster-service=true,name=kube-dns k8s-app=kube-dns 192.168.3.10 53/UDP
kubernetes component=apiserver,provider=kubernetes <none> 192.168.3.2 443/TCP
kubernetes-ro component=apiserver,provider=kubernetes <none> 192.168.3.1 80/TCP
# iptables -t nat -L
Chain KUBE-PORTALS-CONTAINER (1 references)
target prot opt source destination
REDIRECT tcp -- anywhere 192.168.3.184 /* default/frontend: */ tcp dpt:3000 redir ports 50734
REDIRECT tcp -- anywhere kube02 /* default/frontend: */ tcp dpt:3000 redir ports 50734
REDIRECT udp -- anywhere 192.168.3.10 /* default/kube-dns: */ udp dpt:domain redir ports 52415
REDIRECT tcp -- anywhere 192.168.3.2 /* default/kubernetes: */ tcp dpt:https redir ports 33373
REDIRECT tcp -- anywhere 192.168.3.1 /* default/kubernetes-ro: */ tcp dpt:http redir ports 60311
Chain KUBE-PORTALS-HOST (1 references)
target prot opt source destination
DNAT tcp -- anywhere 192.168.3.184 /* default/frontend: */ tcp dpt:3000 to:172.16.2.92:50734
DNAT tcp -- anywhere kube02 /* default/frontend: */ tcp dpt:3000 to:172.16.2.92:50734
DNAT udp -- anywhere 192.168.3.10 /* default/kube-dns: */ udp dpt:domain to:172.16.2.92:52415
DNAT tcp -- anywhere 192.168.3.2 /* default/kubernetes: */ tcp dpt:https to:172.16.2.92:33373
DNAT tcp -- anywhere 192.168.3.1 /* default/kubernetes-ro: */ tcp dpt:http to:172.16.2.92:60311
谢谢