kubenetes入门学习-十-service
最近學(xué)習(xí)k8s遇到很多問(wèn)題,建了一個(gè)qq群:153144292,交流devops、k8s、docker等
service
因?yàn)閜od是有生命周期的,為了讓客戶(hù)端訪(fǎng)問(wèn)不變,就出現(xiàn)了service,service通過(guò)dns(CoreDNS,kube-dns)來(lái)實(shí)現(xiàn)不變的訪(fǎng)問(wèn)。
node network:節(jié)點(diǎn)上
pod network:pod上
cluster network:virtual IP--service ip
每個(gè)節(jié)點(diǎn)上都工作有kube-proxy,kube-proxy一直和api service連接(watch),service資源有任何變動(dòng)都通過(guò)kube-proxy傳達(dá)。
三種模型:userspace、iptables、ipvs
userspace--效率低--所有訪(fǎng)問(wèn)都來(lái)回在kube-proxy接受調(diào)度--1.1-
iptables--由service調(diào)度-1.10-
ipvs-1.11+
類(lèi)型:
? ? ExternalName、ClusterIP、NodePort、and LoadBalancer
===========================
清單創(chuàng)建service資源
[root@master ~]# kubectl explain svc
[root@master ~]# kubectl explain svc.spec
[root@master ~]# kubectl explain svc.spec.selector
---------------------------
其中重要的4個(gè)字段:
apiVersion:
kind:
metadata:
spec:
clusterIP: 可以自定義,也可以動(dòng)態(tài)分配
ports:(與后端容器端口關(guān)聯(lián))
selector:(關(guān)聯(lián)到哪些pod資源上)
type:服務(wù)類(lèi)型
service的類(lèi)型
對(duì)一些應(yīng)用(如 Frontend)的某些部分,可能希望通過(guò)外部(Kubernetes 集群外部)IP 地址暴露 Service。
Kubernetes ServiceTypes 允許指定一個(gè)需要的類(lèi)型的 Service,默認(rèn)是 ClusterIP 類(lèi)型。
Type 的取值以及行為如下:
? ? ClusterIP:通過(guò)集群的內(nèi)部 IP 暴露服務(wù),選擇該值,服務(wù)只能夠在集群內(nèi)部可以訪(fǎng)問(wèn),這也是默認(rèn)的 ServiceType。
? ? NodePort:通過(guò)每個(gè) Node 上的 IP 和靜態(tài)端口(NodePort)暴露服務(wù)。NodePort 服務(wù)會(huì)路由到 ClusterIP 服務(wù),這個(gè) ClusterIP 服務(wù)會(huì)自動(dòng)創(chuàng)建。通過(guò)請(qǐng)求 <NodeIP>:<NodePort>,可以從集群的外部訪(fǎng)問(wèn)一個(gè) NodePort 服務(wù)。
? ? LoadBalancer:使用云提供商的負(fù)載均衡器,可以向外部暴露服務(wù)。外部的負(fù)載均衡器可以路由到 NodePort 服務(wù)和 ClusterIP 服務(wù)。
? ? ExternalName:通過(guò)返回 CNAME 和它的值,可以將服務(wù)映射到 externalName 字段的內(nèi)容(例如, foo.bar.example.com)。 沒(méi)有任何類(lèi)型代理被創(chuàng)建,這只有 Kubernetes 1.7 或更高版本的 kube-dns 才支持。
===========================================
1、ClusterIP的service類(lèi)型演示:
[root@master manifests]# cat redis-demo.yaml?
apiVersion: v1
kind: Service
metadata:
? name: redis
? namespace: default
spec:
? selector:
? ? app: redis
? ? role: logstor
? type: ClusterIP
? ports:
? - port: 6379
? ? targetPort: 6379
[root@k8s-master mainfests]# kubectl apply -f redis-svc.yaml?
service/redis created
[root@k8s-master mainfests]# kubectl get svc
NAME ? ? ? ? TYPE ? ? ? ?CLUSTER-IP ? ? ? EXTERNAL-IP ? PORT(S) ? ?AGE
kubernetes ? ClusterIP ? 10.96.0.1 ? ? ? ?<none> ? ? ? ?443/TCP ? ?36d
redis ? ? ? ?ClusterIP ? 10.107.238.182 ? <none> ? ? ? ?6379/TCP ? 1m
[root@k8s-master mainfests]# kubectl describe svc redis
Name: ? ? ? ? ? ? ?redis
Namespace: ? ? ? ? default
Labels: ? ? ? ? ? ?<none>
Annotations: ? ? ? kubectl.kubernetes.io/last-applied-configuration={"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"name":"redis","namespace":"default"},"spec":{"ports":[{"port":6379,"targetPort":6379}...
Selector: ? ? ? ? ?app=redis,role=logstor
Type: ? ? ? ? ? ? ?ClusterIP
IP: ? ? ? ? ? ? ? ?10.107.238.182 #service ip
Port: ? ? ? ? ? ? ?<unset> ?6379/TCP
TargetPort: ? ? ? ?6379/TCP
Endpoints: ? ? ? ? 10.244.1.16:6379 #此處的ip+端口就是pod的ip+端口
Session Affinity: ?None
Events: ? ? ? ? ? ?<none>
[root@k8s-master mainfests]# kubectl get pod redis-5b5d6fbbbd-v82pw -o wide
NAME ? ? ? ? ? ? ? ? ? ? READY ? ? STATUS ? ?RESTARTS ? AGE ? ? ? IP ? ? ? ? ? ?NODE
redis-5b5d6fbbbd-v82pw ? 1/1 ? ? ? Running ? 0 ? ? ? ? ?20d ? ? ? 10.244.1.16 ? k8s-node01
總結(jié)出:service不會(huì)直接到pod,service是直接到endpoint資源,就是地址加端口,再由endpoint再關(guān)聯(lián)到pod
資源創(chuàng)建之后就會(huì)在etcd創(chuàng)建一條記錄,dns
service的類(lèi)型
對(duì)一些應(yīng)用(如 Frontend)的某些部分,可能希望通過(guò)外部(Kubernetes 集群外部)IP 地址暴露 Service。
Kubernetes ServiceTypes 允許指定一個(gè)需要的類(lèi)型的 Service,默認(rèn)是 ClusterIP 類(lèi)型。
資源記錄:
? ? SVC_NAME.NS_NAME.DOMAIN.LTD.
? ? svc.cluster.local.
? ? redis.default.svc.cluster.local.
=======================================
2、NodePort的service類(lèi)型演示:
? ?NodePort即節(jié)點(diǎn)Port,通常在部署Kubernetes集群系統(tǒng)時(shí)會(huì)預(yù)留一個(gè)端口范圍用于NodePort,其范圍默認(rèn)為:30000~32767之間的端口。定義NodePort類(lèi)型的Service資源時(shí),需要使用.spec.type進(jìn)行明確指定。
[root@master manifests]# cat myapp-svc.yaml?
apiVersion: v1
kind: Service
metadata:
? name: myapp
? namespace: default
spec:
? selector:
? ? app: myapp
? ? release: canary
? clusterIP: 10.99.99.99
? type: NodePort
? ports:
? - port: 80
? ? targetPort: 80
? ? nodePort: 30080
? ??
[root@master manifests]# kubectl apply -f myapp-svc.yaml?
service/myapp created[root@master manifests]# kubectl get svc
NAME ? ? ? ? TYPE ? ? ? ?CLUSTER-IP ? ?EXTERNAL-IP ? PORT(S) ? ? ? ?AGE
kubernetes ? ClusterIP ? 10.96.0.1 ? ? <none> ? ? ? ?443/TCP ? ? ? ?11d
myapp ? ? ? ?NodePort ? ?10.99.99.99 ? <none> ? ? ? ?80:30080/TCP ? 40s
[root@master manifests]# kubectl describe svc myapp
Name: ? ? ? ? ? ? ? ? ? ? myapp
Namespace: ? ? ? ? ? ? ? ?default
Labels: ? ? ? ? ? ? ? ? ? <none>
Annotations: ? ? ? ? ? ? ?kubectl.kubernetes.io/last-applied-configuration:
? ? ? ? ? ? ? ? ? ? ? ? ? ? {"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"name":"myapp","namespace":"default"},"spec":{"clusterIP":"10.99.99.99","...
Selector: ? ? ? ? ? ? ? ? app=myapp,release=canary
Type: ? ? ? ? ? ? ? ? ? ? NodePort
IP: ? ? ? ? ? ? ? ? ? ? ? 10.99.99.99
Port: ? ? ? ? ? ? ? ? ? ? <unset> ?80/TCP
TargetPort: ? ? ? ? ? ? ? 80/TCP
NodePort: ? ? ? ? ? ? ? ? <unset> ?30080/TCP
Endpoints: ? ? ? ? ? ? ? ?10.244.1.24:80,10.244.1.25:80,10.244.2.25:80 + 2 more...
Session Affinity: ? ? ? ? None
External Traffic Policy: ?Cluster
Events: ? ? ? ? ? ? ? ? ? <none>
集群之外找一臺(tái)機(jī)器ping node節(jié)點(diǎn)的30080
[root@master manifests]# kubectl get pods
NAME ? ? ? ? ? ? ? ? ? ? ? ? ? ?READY ? STATUS ? ?RESTARTS ? AGE
liveness-httpget-pod ? ? ? ? ? ?1/1 ? ? Running ? 1 ? ? ? ? ?5d23h
myapp-deploy-69dc8c7655-jkkwv ? 1/1 ? ? Running ? 0 ? ? ? ? ?30h
myapp-deploy-69dc8c7655-q97jc ? 1/1 ? ? Running ? 0 ? ? ? ? ?30h
myapp-deploy-69dc8c7655-sldk8 ? 1/1 ? ? Running ? 0 ? ? ? ? ?30h
myapp-deploy-69dc8c7655-v9dvc ? 1/1 ? ? Running ? 0 ? ? ? ? ?30h
myapp-deploy-69dc8c7655-x5qth ? 1/1 ? ? Running ? 0 ? ? ? ? ?30h
nginx-7849c4bbcd-dscjr ? ? ? ? ?1/1 ? ? Running ? 0 ? ? ? ? ?9d
nginx-7849c4bbcd-vdd45 ? ? ? ? ?1/1 ? ? Running ? 0 ? ? ? ? ?9d
nginx-7849c4bbcd-wrvks ? ? ? ? ?1/1 ? ? Running ? 0 ? ? ? ? ?9d
nginx-deploy-84cbfc56b6-mjcw5 ? 1/1 ? ? Running ? 0 ? ? ? ? ?9d
echo myapp-deploy-69dc8c7655-jkkwv >/usr/share/nginx/html/index.html
echo myapp-deploy-69dc8c7655-q97jc >/usr/share/nginx/html/index.html
echo myapp-deploy-69dc8c7655-sldk8 >/usr/share/nginx/html/index.html
echo myapp-deploy-69dc8c7655-v9dvc >/usr/share/nginx/html/index.html
echo myapp-deploy-69dc8c7655-x5qth >/usr/share/nginx/html/index.html
# cat index.html
1
# exit
[root@master manifests]# kubectl exec -it myapp-deploy-69dc8c7655-jkkwv -- /bin/sh
[root@master manifests]#kubectl exec -it myapp-deploy-69dc8c7655-q97jc -- /bin/sh
# echo myapp-deploy-69dc8c7655-q97jc >/usr/share/nginx/html/index.html
# exit
[root@master manifests]# kubectl exec -it myapp-deploy-69dc8c7655-sldk8 -- /bin/sh
# echo myapp-deploy-69dc8c7655-sldk8 >/usr/share/nginx/html/index.html
# exit
[root@master manifests]# kubectl exec -it myapp-deploy-69dc8c7655-v9dvc ?-- /bin/sh
# echo myapp-deploy-69dc8c7655-v9dvc >/usr/share/nginx/html/index.html
# exit
[root@master manifests]# kubectl exec -it myapp-deploy-69dc8c7655-x5qth ?-- /bin/sh
# echo myapp-deploy-69dc8c7655-x5qth >/usr/share/nginx/html/index.html
[root@haproslave ~]# while true;do curl http://10.249.6.101:30080/index.html; sleep 1; done
myapp-deploy-69dc8c7655-sldk8
1
myapp-deploy-69dc8c7655-x5qth
myapp-deploy-69dc8c7655-x5qth
myapp-deploy-69dc8c7655-sldk8
1
myapp-deploy-69dc8c7655-x5qth
myapp-deploy-69dc8c7655-sldk8
myapp-deploy-69dc8c7655-q97jc
myapp-deploy-69dc8c7655-v9dvc
myapp-deploy-69dc8c7655-q97jc
myapp-deploy-69dc8c7655-q97jc
myapp-deploy-69dc8c7655-v9dvc
可以看到通過(guò)NodePort方式已經(jīng)實(shí)現(xiàn)了從集群外部端口進(jìn)行訪(fǎng)問(wèn),訪(fǎng)問(wèn)鏈接如下:http://nodeip:30080/。
實(shí)踐中并不鼓勵(lì)用戶(hù)自定義使用節(jié)點(diǎn)的端口,因?yàn)槿菀缀推渌F(xiàn)存的Service沖突,建議留給系統(tǒng)自動(dòng)配置。
現(xiàn)在在集群外做一個(gè)lvs或者h(yuǎn)aproxy即可實(shí)現(xiàn)負(fù)載均衡
==========================
3、LoadBalancer ?我們這里做不到
一般在公有云上做:云負(fù)載均衡--代理到nodeip--serviceip--pod
==========================
4、ExternalName
服務(wù)在k8s之外,我們期望內(nèi)部的pod能夠訪(fǎng)問(wèn)到,這里我就要建立一個(gè)ExternalName service服務(wù),通過(guò)關(guān)聯(lián)到外部服務(wù),各種轉(zhuǎn)換,由nodeip轉(zhuǎn)換。
這樣就可以像使用內(nèi)部服務(wù)一樣使用外部服務(wù)。
===========================
5、Pod的會(huì)話(huà)保持
Service資源還支持Session affinity(粘性會(huì)話(huà))機(jī)制,可以將來(lái)自同一個(gè)客戶(hù)端的請(qǐng)求始終轉(zhuǎn)發(fā)至同一個(gè)后端的Pod對(duì)象,這意味著它會(huì)影響調(diào)度算法的流量分發(fā)功用,進(jìn)而降低其負(fù)載均衡的效果。因此,當(dāng)客戶(hù)端訪(fǎng)問(wèn)Pod中的應(yīng)用程序時(shí),如果有基于客戶(hù)端身份保存某些私有信息,并基于這些私有信息追蹤用戶(hù)的活動(dòng)等一類(lèi)的需求時(shí),那么應(yīng)該啟用session affinity機(jī)制。
Service affinity的效果僅僅在一段時(shí)間內(nèi)生效,默認(rèn)值為10800秒,超出時(shí)長(zhǎng),客戶(hù)端再次訪(fǎng)問(wèn)會(huì)重新調(diào)度。該機(jī)制僅能基于客戶(hù)端IP地址識(shí)別客戶(hù)端身份,它會(huì)將經(jīng)由同一個(gè)NAT服務(wù)器進(jìn)行原地址轉(zhuǎn)換的所有客戶(hù)端識(shí)別為同一個(gè)客戶(hù)端,由此可知,其調(diào)度的效果并不理想。Service 資源 通過(guò). spec. sessionAffinity 和. spec. sessionAffinityConfig 兩個(gè)字段配置粘性會(huì)話(huà)。 spec. sessionAffinity 字段用于定義要使用的粘性會(huì)話(huà)的類(lèi)型,它僅支持使用“ None” 和“ ClientIP” 兩種屬性值。如下:
[root@master manifests]# cat myapp-svc.yaml?
apiVersion: v1
kind: Service
metadata:
? name: myapp
? namespace: default
spec:
? selector:
? ? app: myapp
? ? release: canary
? sessionAffinity: ClientIP ? 這里新增,也可以使用命令
? clusterIP: 10.99.99.99
? type: NodePort
? ports:
? - port: 80
? ? targetPort: 80
? ? nodePort: 30080
使用上面修改配置文件就需要執(zhí)行
[root@master mainfests]# kubectl apply -f myapp-svc.yaml?
直接使用命令
[root@master manifests]# kubectl patch svc myapp -p '{"spec":{"sessionAffinity":"ClientIP"}}' ?#session保持,同一ip訪(fǎng)問(wèn)同一個(gè)pod
service/myapp patched?
[root@master manifests]# kubectl describe svc myapp
Name: ? ? ? ? ? ? ? ? ? ? myapp
Namespace: ? ? ? ? ? ? ? ?default
Labels: ? ? ? ? ? ? ? ? ? <none>
Annotations: ? ? ? ? ? ? ?kubectl.kubernetes.io/last-applied-configuration:
? ? ? ? ? ? ? ? ? ? ? ? ? ? {"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"name":"myapp","namespace":"default"},"spec":{"clusterIP":"10.99.99.99","...
Selector: ? ? ? ? ? ? ? ? app=myapp,release=canary
Type: ? ? ? ? ? ? ? ? ? ? NodePort
IP: ? ? ? ? ? ? ? ? ? ? ? 10.99.99.99
Port: ? ? ? ? ? ? ? ? ? ? <unset> ?80/TCP
TargetPort: ? ? ? ? ? ? ? 80/TCP
NodePort: ? ? ? ? ? ? ? ? <unset> ?30080/TCP
Endpoints: ? ? ? ? ? ? ? ?10.244.1.24:80,10.244.1.25:80,10.244.2.25:80 + 2 more...
Session Affinity: ? ? ? ? ClientIP ?這里生效了
External Traffic Policy: ?Cluster
Events: ? ? ? ? ? ? ? ? ? <none>
[root@haproslave ~]# while true;do curl http://10.249.6.101:30080/; sleep 1; done
1
1
1
1
1
1
取消session,可以是命令行或者是修改yaml
kubectl patch svc myapp -p '{"spec":{"sessionAffinity":"None"}}'
可以看到立馬生效了
[root@haproslave ~]# while true;do curl http://10.249.6.101:30080/; sleep 1; done
1
1
1
1
1
myapp-deploy-69dc8c7655-v9dvc
myapp-deploy-69dc8c7655-x5qth
myapp-deploy-69dc8c7655-x5qth
myapp-deploy-69dc8c7655-sldk8
myapp-deploy-69dc8c7655-x5qth
===========================
6、Headless Service(無(wú)頭)
? 有時(shí)不需要或不想要負(fù)載均衡,以及單獨(dú)的 Service IP。 遇到這種情況,可以通過(guò)指定 Cluster IP(spec.clusterIP)的值為 "None" 來(lái)創(chuàng)建 Headless Service。
? 這個(gè)選項(xiàng)允許開(kāi)發(fā)人員自由尋找他們自己的方式,從而降低與 Kubernetes 系統(tǒng)的耦合性。 應(yīng)用仍然可以使用一種自注冊(cè)的模式和適配器,對(duì)其它需要發(fā)現(xiàn)機(jī)制的系統(tǒng)能夠很容易地基于這個(gè) API 來(lái)構(gòu)建。
[root@master manifests]# cat myapp-svc-headless.yaml?
apiVersion: v1
kind: Service
metadata:
? name: myapp-headless
? namespace: default
spec:
? selector:
? ? app: myapp
? ? release: canary
? clusterIP: "None"
? ports:
? - port: 80
? ? targetPort: 80
? ??
[root@master manifests]# kubectl apply -f myapp-svc-headless.yaml?
service/myapp-headless created
[root@master manifests]# kubectl get svc -n kube-system
NAME ? ? ? TYPE ? ? ? ?CLUSTER-IP ? EXTERNAL-IP ? PORT(S) ? ? ? ? AGE
kube-dns ? ClusterIP ? 10.96.0.10 ? <none> ? ? ? ?53/UDP,53/TCP ? 11d
[root@master manifests]# kubectl get pods -o wide -l app=myapp
NAME ? ? ? ? ? ? ? ? ? ? ? ? ? ?READY ? STATUS ? ?RESTARTS ? AGE ? IP ? ? ? ? ? ?NODE ? ? NOMINATED NODE ? READINESS GATES
myapp-deploy-69dc8c7655-jkkwv ? 1/1 ? ? Running ? 0 ? ? ? ? ?31h ? 10.244.1.24 ? node01 ? <none> ? ? ? ? ? <none>
myapp-deploy-69dc8c7655-q97jc ? 1/1 ? ? Running ? 0 ? ? ? ? ?31h ? 10.244.2.25 ? node02 ? <none> ? ? ? ? ? <none>
myapp-deploy-69dc8c7655-sldk8 ? 1/1 ? ? Running ? 0 ? ? ? ? ?30h ? 10.244.2.27 ? node02 ? <none> ? ? ? ? ? <none>
myapp-deploy-69dc8c7655-v9dvc ? 1/1 ? ? Running ? 0 ? ? ? ? ?30h ? 10.244.2.28 ? node02 ? <none> ? ? ? ? ? <none>
myapp-deploy-69dc8c7655-x5qth ? 1/1 ? ? Running ? 0 ? ? ? ? ?31h ? 10.244.1.25 ? node01 ? <none> ? ? ? ? ? <none>
[root@master manifests]# dig -t A myapp-headless.default.svc.cluster.local. @10.96.0.10
; <<>> DiG 9.9.4-RedHat-9.9.4-73.el7_6 <<>> -t A myapp-headless.default.svc.cluster.local. @10.96.0.10
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 41896
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 5, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;myapp-headless.default.svc.cluster.local. IN A
;; ANSWER SECTION:
myapp-headless.default.svc.cluster.local. 5 IN A 10.244.2.25
myapp-headless.default.svc.cluster.local. 5 IN A 10.244.1.24
myapp-headless.default.svc.cluster.local. 5 IN A 10.244.2.28
myapp-headless.default.svc.cluster.local. 5 IN A 10.244.2.27
myapp-headless.default.svc.cluster.local. 5 IN A 10.244.1.25
;; Query time: 0 msec
;; SERVER: 10.96.0.10#53(10.96.0.10)
;; WHEN: Mon Mar 11 10:26:13 EDT 2019
;; MSG SIZE ?rcvd: 338
對(duì)比含有ClusterIP的service解析
[root@master manifests]# dig -t A myapp.default.svc.cluster.local. @10.96.0.10
; <<>> DiG 9.9.4-RedHat-9.9.4-73.el7_6 <<>> -t A myapp.default.svc.cluster.local. @10.96.0.10
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 30311
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;myapp.default.svc.cluster.local. IN?? ?A
;; ANSWER SECTION:
myapp.default.svc.cluster.local. 5 IN?? ?A?? ?10.99.99.99
;; Query time: 0 msec
;; SERVER: 10.96.0.10#53(10.96.0.10)
;; WHEN: Mon Mar 11 10:27:51 EDT 2019
;; MSG SIZE ?rcvd: 96
[root@master manifests]# kubectl get svc
NAME ? ? ? ? ? ? TYPE ? ? ? ?CLUSTER-IP ? ?EXTERNAL-IP ? PORT(S) ? ? ? ?AGE
kubernetes ? ? ? ClusterIP ? 10.96.0.1 ? ? <none> ? ? ? ?443/TCP ? ? ? ?11d
myapp ? ? ? ? ? ?NodePort ? ?10.99.99.99 ? <none> ? ? ? ?80:30080/TCP ? 46m
myapp-headless ? ClusterIP ? None ? ? ? ? ?<none> ? ? ? ?80/TCP ? ? ? ? 2m35
從以上的演示可以看到對(duì)比普通的service和headless service,headless service做dns解析是直接解析到pod的,而servcie是解析到ClusterIP的,那么headless有什么用呢???這將在statefulset中應(yīng)用到,這里暫時(shí)僅僅做了解什么是headless service和創(chuàng)建方法。
===========================
[root@master ~]# kubectl get svc
NAME ? ? ? ? ? TYPE ? ? ? ?CLUSTER-IP ? ? ? EXTERNAL-IP ? PORT(S) ? AGE
kubernetes ? ? ClusterIP ? 10.96.0.1 ? ? ? ?<none> ? ? ? ?443/TCP ? 11d
nginx-deploy ? ClusterIP ? 10.100.251.191 ? <none> ? ? ? ?80/TCP ? ?10d
[root@master ~]# kubectl delete svc nginx-deploy
service "nginx-deploy" deleted
[root@master ~]# kubectl get svc
NAME ? ? ? ? TYPE ? ? ? ?CLUSTER-IP ? EXTERNAL-IP ? PORT(S) ? AGE
kubernetes ? ClusterIP ? 10.96.0.1 ? ?<none> ? ? ? ?443/TCP ? 11d
[root@master ~]# kubectl explain svc
KIND: ? ? Service
VERSION: ?v1
DESCRIPTION:
? ? ?Service is a named abstraction of software service (for example, mysql)
? ? ?consisting of local port (for example 3306) that the proxy listens on, and
? ? ?the selector that determines which pods will answer requests sent through
? ? ?the proxy.
FIELDS:
? ?apiVersion?? ?<string>
? ? ?APIVersion defines the versioned schema of this representation of an
? ? ?object. Servers should convert recognized schemas to the latest internal
? ? ?value, and may reject unrecognized values. More info:
? ? ?https://git.k8s.io/community/contributors/devel/api-conventions.md#resources
? ?kind?? ?<string>
? ? ?Kind is a string value representing the REST resource this object
? ? ?represents. Servers may infer this from the endpoint the client submits
? ? ?requests to. Cannot be updated. In CamelCase. More info:
? ? ?https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds
? ?metadata?? ?<Object>
? ? ?Standard object's metadata. More info:
? ? ?https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata
? ?spec?? ?<Object>
? ? ?Spec defines the behavior of a service.
? ? ?https://git.k8s.io/community/contributors/devel/api-conventions.md#spec-and-status
? ?status?? ?<Object>
? ? ?Most recently observed status of the service. Populated by the system.
? ? ?Read-only. More info:
? ? ?https://git.k8s.io/community/contributors/devel/api-conventions.md#spec-and-status
?
群名稱(chēng):k8s學(xué)習(xí)群? ?群???號(hào):153144292
總結(jié)
以上是生活随笔為你收集整理的kubenetes入门学习-十-service的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 刷题笔记-活字印刷
- 下一篇: idea maven无法从私服下载jar