做网站保证效果,苏州市工业园区规划建设局网站,seo建设者,青岛茶叶网站建设k8s-service、endpoints、pod之间是怎么进行网络互通的 1、service2、endpoints3、service、endpoints、pod通信图4、不通服务pod内部间访问 1、service
在K8S中#xff0c;Service是一种抽象#xff0c;定义了一组Pod的逻辑集合和访问这些Pod的策略。首先#xff0c;我们需… k8s-service、endpoints、pod之间是怎么进行网络互通的 1、service2、endpoints3、service、endpoints、pod通信图4、不通服务pod内部间访问 1、service
在K8S中Service是一种抽象定义了一组Pod的逻辑集合和访问这些Pod的策略。首先我们需要创建一个Service并指定该Service的selector来确定要选中的Pod。 k8s集群也会为service分配个cidr,每个service都有对应的IP。 查看service。 kubectl get svc[rootk8s-node2 k8s]# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 none 443/TCP 33h
nginx NodePort 10.102.104.249 none 80:30940/TCP 5h20m查看指定service详情。
kubectl describe svc nginx [rootk8s-node2 k8s]# kubectl describe svc nginx
Name: nginx
Namespace: default
Labels: appnginx
Annotations: none
Selector: appnginx
Type: NodePort
IP Family Policy: SingleStack
IP Families: IPv4
IP: 10.102.104.249
IPs: 10.102.104.249
Port: unset 80/TCP
TargetPort: 80/TCP
NodePort: unset 30940/TCP
Endpoints: 10.244.169.129:80,10.244.36.65:80
Session Affinity: None
External Traffic Policy: Cluster
Events: none2、endpoints
Endpoints是将Service与其后端Pod关联的方式。我们需要在创建Service后自动创建与Service相关的Endpoints。
查看ep,可以发现nginx对应的endpoints是pod的ip地址和端口。
[rootk8s-node2 k8s]# kubectl get ep
NAME ENDPOINTS AGE
kubernetes 192.168.8.132:6443 33h
nginx 10.244.169.129:80,10.244.36.65:80 5h22m3、service、endpoints、pod通信图
盗用的大佬的哈哈
4、不通服务pod内部间访问
比如部署了nginx和mysql。 从nginx的pod要去访问mysql直接可以访问mysql的service的name去访问。
演示服务间通信我是用busybox的pod去访问nginx。
apiVersion: v1
kind: Pod
metadata:name: busyboxlabels:purpose: demonstrate-busybox
spec:containers:- name: busyboximage: busyboxcommand:- sleep- 3600resources:limits:memory: 128Micpu: 500mkubectl apply -f busybox.yaml进入busybox容器
kubectl exec -it busybox -- sh通过nginx的service的name访问nginx
wget http://nginx访问成功 注意不同pod服务之间可以跨命名空间去访问的访问格式service的name.命名空间name,nginx放到默认命名空间default里的。
wget http://nginx.default