linux怎么查看本机内存大小
246
2022-09-10
Kubernetes----HeadLess类型的Service
一、Headless类型Service简介
在某些场景下,开发人员可能不想使用Service提供的负载均衡功能,而希望自己来控制负载均衡策略,针对这种情况,Kubernetes提供了Headless Service,这类Service不会分配ClusterIP,如果想要访问Service,只能通过service的域名进行查询
二、环境准备
编写deployment.yaml文件,内容如下:
apiVersion: v1kind: Namespacemetadata: name: dev---apiVersion: apps/v1kind: Deploymentmetadata: name: pc-deployment namespace: devspec: replicas: 3 selector: matchLabels: app: nginx-pod template: metadata: labels: app: nginx-pod spec: containers: - name: nginx image: nginx:1.17.1 ports: - containerPort: 80
然后使用如下命令创建资源
[root@master service]# kubectl apply -f deployment.yamlnamespace/dev createddeployment.apps/pc-deployment created[root@master service]#
查看创建的资源如下:
[root@master service]# kubectl get deploy,pod -n dev -o wideNAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTORdeployment.apps/pc-deployment 3/3 3 3 17m nginx nginx:1.17.1 app=nginx-podNAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATESpod/pc-deployment-5ffc5bf56c-mqwst 1/1 Running 0 17m 10.244.2.191 node2
三、创建Headless类型的Service
编辑headless.yaml文件,内容如下:
apiVersion: v1kind: Servicemetadata: name: service-headless namespace: devspec: selector: app: nginx-pod clusterIP: None type: ClusterIP ports: - port: 80 targetPort: 80
使用如下命令创建服务
[root@master service]# kubectl apply -f headless.yamlservice/service-headless created[root@master service]#
查看创建的资源
[root@master service]# kubectl get service,deployment,pod -n dev -o wideNAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTORservice/service-headless ClusterIP None
此时服务因为没有ClusterIP,所以此时不能使用ip去访问了,只能使用域名访问了,即 service-headless.dev.svc.cluster.local,这里面格式是
[service的名字].[命名空间].svc.cluster.local
首先登录pod查看域名解析
[root@master service]# kubectl exec -it pod/pc-deployment-5ffc5bf56c-mqwst -n dev /bin/bashkubectl exec [POD] [COMMAND] is DEPRECATED and will be removed in a future version. Use kubectl exec [POD] -- [COMMAND] instead.root@pc-deployment-5ffc5bf56c-9bg6w:/#root@pc-deployment-5ffc5bf56c-9bg6w:/# cat /etc/resolv.confnameserver 10.96.0.10search dev.svc.cluster.local svc.cluster.local cluster.localoptions ndots:5root@pc-deployment-5ffc5bf56c-9bg6w:/#
然后查看域名解析,具体查看域名的命令如下
[root@master service]# dig @10.96.0.10 service-headless.dev.svc.cluster.local; <<>> DiG 9.11.4-P2-RedHat-9.11.4-26.P2.el7_9.9 <<>> @10.96.0.10 service-headless.dev.svc.cluster.local; (1 server found);; global options: +cmd;; Got answer:;; WARNING: .local is reserved for Multicast DNS;; You are currently testing what happens when an mDNS query is leaked to DNS;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 62573;; flags: qr aa rd; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 1;; WARNING: recursion requested but not available;; OPT PSEUDOSECTION:; EDNS: version: 0, flags:; udp: 4096;; QUESTION SECTION:;service-headless.dev.svc.cluster.local. IN A;; ANSWER SECTION:service-headless.dev.svc.cluster.local. 30 IN A 10.244.2.190service-headless.dev.svc.cluster.local. 30 IN A 10.244.1.53service-headless.dev.svc.cluster.local. 30 IN A 10.244.2.191;; Query time: 0 msec;; SERVER: 10.96.0.10#53(10.96.0.10);; WHEN: Mon Apr 04 11:57:01 CST 2022;; MSG SIZE rcvd: 229[root@master service]#
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~