深入解析StatefulSet與K8s服務管理

目錄

一、Statefulset控制器:概念、原理解讀

有狀態服務

無狀態服務

StatefulSet部分組成

Headless service

二、Statefulset資源清單文件編寫技巧

三、Statefulset使用案例:部署web站點

四、Statefulset管理pod:擴容、縮容、更新

Statefulset實現pod的動態擴容

Statefulset實現pod的動態縮容

Statefulset實現pod的更新

一、概述

二、 Kube-proxy的三種模式

2.1 userspace 模式

2.2 iptables 模式

2.3 ipvs 模式

三、Service資源類型

四、Service實戰案例

實驗環境準備

4.1 ClusterIP類型的Service

4.2 HeadLiness類型的Service

4.3 NodePort類型的Service

4.4 LoadBalancer類型的Service

4.5 ExternalName類型的Service


一、Statefulset控制器:概念、原理解讀

StatefulSet是為了管理有狀態服務的問題而設計的。

有狀態服務

StatefulSet是有狀態的集合,管理有狀態的服務,它所管理的Pod的名稱不能隨意變化。數據持久化的目錄也是不一樣,每一個Pod都有自己獨有的數據持久化存儲目錄。比如MySQL主從、redis集群等。

無狀態服務

RC、Deployment、DaemonSet都是管理無狀態的服務,它們所管理的Pod的IP、名字,啟停順序等都是隨機的。個體對整體無影響,所有pod都是共用一個數據卷的,部署的tomcat就是無狀態的服務,tomcat被刪除,在啟動一個新的tomcat,加入到集群即可,跟tomcat的名字無關。

StatefulSet部分組成

  1. Headless Service:用來定義pod網路標識,生成可解析的DNS記錄

  2. volumeClaimTemplates:存儲卷申請模板,創建pvc,指定pvc名稱大小,自動創建pvc,且pvc由存儲類供應。

  3. StatefulSet:管理pod的

Headless service

Headless service不分配clusterIP,headless service可以通過解析service的DNS,返回所有Pod的dns和ip地址 (只有statefulSet部署的Pod才有DNS地址),普通的service,只能通過解析service的DNS返回service的ClusterIP。

為什么要用headless service(沒有service ip的service)?

在使用Deployment時,創建的Pod名稱是沒有順序的,是隨機字符串,在用statefulset管理pod時要求pod名稱必須是有序的每一個pod不能被隨意取代,pod重建后pod名稱還是一樣的。因為pod IP是變化的,所以要用Pod名稱來識別。pod名稱是pod唯一性的標識符,必須持久穩定有效。這時候要用到無頭服務,它可以給每個Pod一個唯一的名稱。

1、headless service會為service分配一個域名

<service name>.$<namespace name>.svc.cluster.local

K8s中資源的全局FQDN格式:

 Service_NAME.NameSpace_NAME.Domain.LTD.Domain.LTD.=svc.cluster.local.     #這是默認k8s集群的域名。
FQDN 全稱?Fully Qualified Domain Name
?
即全限定域名:同時帶有主機名和域名的名稱
?
FQDN = Hostname + DomainName
?
如:主機名是 duoduo
?
域名是 [baidu.com](http://baidu.com/)
?
FQDN= duoduo.baidu.com.
?
#eg:
[root@k8s-master deployment]# dig nginx-deploy-svc.default.svc.cluster.local @10.96.0.10
?
; <<>> DiG 9.11.36-RedHat-9.11.36-14.el8_10 <<>> nginx-deploy-svc.default.svc.cluster.local @10.96.0.10
;; 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: 19414
;; flags: qr aa rd; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; WARNING: recursion requested but not available
?
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
; COOKIE: 16379d4770867ed4 (echoed)
;; QUESTION SECTION:
;nginx-deploy-svc.default.svc.cluster.local. IN A
?
;; ANSWER SECTION:
nginx-deploy-svc.default.svc.cluster.local. 30 IN A 10.97.172.98
?
;; Query time: 7 msec
;; SERVER: 10.96.0.10#53(10.96.0.10)
;; WHEN: 一 1月 13 01:25:21 EST 2025
;; MSG SIZE  rcvd: 141
?
[root@k8s-master deployment]# kubectl get svc
NAME ? ? ? ? ? ? ? TYPE ? ? ?  CLUSTER-IP ? ? EXTERNAL-IP ? PORT(S) ? ? ?  AGE
kubernetes ? ? ? ? ClusterIP ? 10.96.0.1 ? ?  <none> ? ? ? ?443/TCP ? ? ?  6d4h
nginx-deploy-svc ? NodePort ? ?10.97.172.98 ? <none> ? ? ? ?80:30676/TCP ? 2m20s

2、StatefulSet會為關聯的Pod保持一個不變的Pod Name

statefulset中Pod的名字格式為 【 $(StatefulSet name)-$(pod序號) 】

3、StatefulSet會為關聯的Pod分配一個dnsName

$<Pod Name>.$<service name>.$<namespace name>.svc.cluster.local

二、Statefulset資源清單文件編寫技巧

#查看定義Statefulset資源需要的字段
?
[root@k8s-master01~]# kubectl explain statefulset
?
FIELDS:
?apiVersion???????<string> #定義statefulset資源需要使用的api版本
?kind??<string>????????? #定義的資源類型
?metadata?????????<Object>???? #元數據
?spec?<Object>????????? #定義容器相關的信息
?
#查看statefulset.spec字段如何定義
?
[root@k8s-master01~]# kubectl explain statefulset.spec
?
FIELDS:
?podManagementPolicy?<string> #pod管理策略
?replicas????<integer>? #副本數
?revisionHistoryLimit???????<integer> #保留的歷史版本
?selector????<Object> -required- #標簽選擇器,選擇它所關聯的pod
?serviceName???<string> -required-? #headless service的名字
?template??<Object> -required-???? #生成pod的模板
?updateStrategy???????<Object>?? #更新策略
?volumeClaimTemplates?<[]Object> #存儲卷申請模板
?
#查看statefulset的spec.template字段如何定義?
?
#對于template而言,其內部定義的就是pod,pod模板是一個獨立的對象
?
[root@k8s-master01~]# kubectl explain statefulset.spec.template
?
FIELDS:
?metadata?????????<Object>
?spec?<Object>? #定義容器屬性的

通過上面可以看到,statefulset資源中有兩個spec字段。第一個spec聲明的是statefulset定義多少個Pod副本(默認將僅部署1個Pod)、匹配Pod標簽的選擇器、創建pod的模板、存儲卷申請模板,第二個spec是spec.template.spec:主要用于Pod里的容器屬性等配置。

.spec.template里的內容是聲明Pod對象時要定義的各種屬性,所以這部分也叫做PodTemplate(Pod模板)。還有一個值得注意的地方是:在.spec.selector中定義的標簽選擇器必須能夠匹配到spec.template.metadata.labels里定義的Pod標簽,否則Kubernetes將不允許創建statefulset。

三、Statefulset使用案例:部署web站點

#編寫一個Statefulset資源清單文件
?
[root@k8s-master01~]# cat statefulset.yaml
?
apiVersion: v1
kind: Service
metadata:name: nginx-svclabels:app: nginx
spec:ports:- port: 80name: webclusterIP: "None"selector:app: nginx
---
apiVersion: apps/v1
kind: StatefulSet
metadata:name: web
spec:selector:matchLabels:app: nginxserviceName: "nginx-svc"replicas: 2template:metadata:labels:app: nginxspec:containers:- name: nginximage: nginximagePullPolicy: IfNotPresentports:- containerPort: 80name: web
?
#更新資源清單文件
?
[root@k8s-master01~]# kubectl apply -f statefulset.yaml
?
service/nginx created
?
statefulset.apps/web created
?
#查看statefulset是否創建成功
?
[root@k8s-master01~]# kubectl get statefulset
?
NAME?? READY?? AGE
?
web????? 2/2????? 42s
?
#查看pod
?
[root@k8s-master01~]# kubectl get pods -l app=nginx
?
NAME??? READY?? STATUS??? RESTARTS?? AGE
?
web-0?? 1/1???? Running?? 0????????? 2m17s
?
web-1?? 1/1???? Running?? 0????????? 115s
?
#通過上面可以看到創建的pod是有序的
?
#查看headless service
?
[root@k8s-master01~]# kubectl get svc -l app=nginx
?
NAME??? TYPE??????? CLUSTER-IP?? EXTERNAL-IP?? PORT(S)?? AGE
?
nginx??? ClusterIP????? None???????? <none>??????? 80/TCP??? 3m19s
?
#查看pvc
?
[root@k8s-master01~]# kubectl get pvc
?
#查看pod主機名
?
[root@k8s-master01~]# for i in 0 1; do kubectl exec web-$i -- sh -c 'hostname';done
?
web-0
?
web-1
?
#使用k運行一個提供nslookup命令的容器(bubybox:1.28),這個命令來自于dnsutils包,通過對pod主機名執行nslookup,可以檢查它們在集群內部的DNS地址:
?
[root@hd1 ~]# cat pod-second.yaml
?
apiVersion: v1
kind: Pod
metadata:name: pod-secondlabels:app: backendtier: db
spec:containers:- name: busyboximage: busybox:1.28imagePullPolicy: IfNotPresentcommand: ["sh","-c","sleep 3600"]
?
[root@hd1 ~]# kubectl apply -f pod-second.yaml
?
[root@hd1 ~]# kubectl exec -it pod-second -- /bin/sh
?
/ # nslookup??web-0.nginx.default.svc.cluster.local
?
Server:????10.10.0.10
?
Address 1: 10.10.0.10 kube-dns.kube-system.svc.cluster.local
?
Name:??????web-0.nginx.default.svc.cluster.local
?
Address 1: 10.10.156.137 web-0.nginx.default.svc.cluster.local
?
/ #
?
#statefulset創建的pod也是有dns記錄的
?
Address: 10.10.209.154? #解析的是pod的ip地址,還可以解析 nginx.default.svc.cluster.local
?
/ # nslookup??nginx.default.svc.cluster.local
?
Server:????10.10.0.10
?
Address 1: 10.10.0.10 kube-dns.kube-system.svc.cluster.local
?
Name:??????nginx.default.svc.cluster.local
?
Address 1: 10.10.25.245 web-1.nginx.default.svc.cluster.local
?
Address 2: 10.10.156.137 web-0.nginx.default.svc.cluster.local
?
/ #

舉例說明service 和headless service區別?

#通過deployment創建pod,pod前端創建一個service
[root@k8s-master01~]# cat deploy-service.yaml
?
apiVersion: v1
?
kind: Service
?
metadata:
?name: my-nginx
?labels:
?run: my-nginx
?
spec:
?type: ClusterIP
?ports:
?- port: 80?? #service的端口,暴露給k8s集群內部服務訪問
?protocol: TCP
?targetPort: 80??? #pod容器中定義的端口
?selector:
?run: my-nginx? #選擇擁有run=my-nginx標簽的pod
?
---
?
apiVersion: apps/v1
?
kind: Deployment
?
metadata:
?name: my-nginx
?
spec:
?selector:
?matchLabels:
?run: my-nginx
?replicas: 2
?template:
?metadata:
?labels:
?run: my-nginx
?spec:
?containers:
?- name: my-nginx
?image: busybox
?imagePullPolicy: IfNotPresent
?ports:
?- containerPort: 80
?command:
?- sleep: 0"
?
#更新資源清單文件
?
[root@k8s-master01~]# kubectl apply -f deploy-service.yaml
?
#查看service
?
[root@k8s-master01~]# kubectl get svc -l run=my-nginx
?
NAME?????? TYPE??????? CLUSTER-IP???? EXTERNAL-IP?? PORT(S)?
?
my-nginx?? ClusterIP???? 10.100.89.90?? <none>??????? 80/TCP??
?
#查看pod
?
[root@k8s-master01~]# kubectl get pods -l run=my-nginx
?
NAME??????????????????????? READY?? STATUS??? RESTARTS?? AGE
?
my-nginx-58f74fc5b6-jzbvk?? 1/1???? Running?? 0????????? 70s
?
my-nginx-58f74fc5b6-n9lqv?? 1/1???? Running?? 0????????? 53s
?
#通過上面可以看到deployment創建的pod是隨機生成的
?
#進入到web-1的pod
?
[root@k8s-master01~]# kubectl exec -it web-1 -- /bin/bash
?
root@web-1:/# nslookup my-nginx.default.svc.cluster.local
?
Server:???????????10.10.0.10
?
Address:????????10.10.0.10#53
?
Name:???my-nginx.default.svc.cluster.local
?
Address: 10.100.89.90?? #解析的是service的ip地址

四、Statefulset管理pod:擴容、縮容、更新

Statefulset實現pod的動態擴容

如果我們覺得兩個副本太少了,想要增加,只需要修改配置文件statefulset.yaml里的replicas的值即可,原來replicas: 2,現在變成replicaset: 3,修改之后,執行如下命令更新:

[root@k8s-master01~]# kubectl apply -f statefulset.yaml
?
service/nginx unchanged
?
statefulset.apps/web configured
?
[root@k8s-master01~]# kubectl get sts
?
NAME?? READY?? AGE
?
web??? 3/3???? 60m
?[root@k8s-master01~]# kubectl get pods -l app=nginx
?
NAME??? READY?? STATUS??? RESTARTS?? AGE
?
web-0?? 1/1???? Running?? 0????????? 61m
?
web-1?? 1/1???? Running?? 0????????? 60m
?
web-2?? 1/1???? Running?? 0????????? 79s
?#也可以直接編輯控制器實現擴容
?
[root@k8s-master01~]# kubectl edit sts web
?
#這個是我們把請求提交給了apiserver,實時修改,把上面的spec下的replicas 后面的值改成4,保存退出
[root@k8s-master01~]#? kubectl get pods -l app=nginx
?
NAME??? READY?? STATUS??? RESTARTS?? AGE
?
web-0?? 1/1???? Running?? 0????????? 62m
?
web-1?? 1/1???? Running?? 0????????? 62m
?
web-2?? 1/1???? Running?? 0????????? 3m13s
?
web-3?? 1/1???? Running?? 0????????? 26s

Statefulset實現pod的動態縮容

如果我們覺得4個Pod副本太多了,想要減少,只需要修改配置文件statefulset.yaml里的replicas的值即可,把replicaset:4變成replicas: 2,修改之后,執行如下命令更新:

[root@k8s-master01~]# kubectl apply -f statefulset.yaml
?
service/nginx unchanged
?
statefulset.apps/web configured
?
[root@k8s-master01~]#? kubectl get pods -l app=nginx
?
NAME??? READY?? STATUS??? RESTARTS?? AGE
?
web-0?? 1/1???? Running?? 0????????? 64m
?
web-1?? 1/1???? Running?? 0????????? 64m

Statefulset實現pod的更新

myapp.tar.gz上傳到k8s-worker01上,手動解壓[root@k8s-worker01 ~]# docker load -i myapp.tar.gz
?
[root@k8s-master01~]# kubectl edit sts web
?
#修改鏡像nginx變成- image: ikubernetes/myapp:v2,修改之后保存退出
?
[root@k8s-master01~]# kubectl get pods -o wide -l app=nginx
?
NAME??? READY?? STATUS??? RESTARTS?? AGE?? IP?????????????? NODE?????? NOMINATED NODE?? READINESS GATES
?
web-0?? 1/1???? Running?? 0????????? 18s?? 10.10.209.156? k8s-worker01??
?
web-1?? 1/1???? Running?? 0????????? 36s?? 10.10.187.115? k8s-worker02
?
#查看pod詳細信息
?
[root@k8s-master01~]# kubectl describe pods web-0
?
#可以看到pod已經使用剛才更新的鏡像ikubernetes/myapp:v2

一、概述

在kubernetes中,pod是應用程序的載體,我們可以通過pod的ip來訪問應用程序,但是pod的ip地址不是固定的,這也就意味著不方便直接采用pod的ip對服務進行訪問。

為了解決這個問題,kubernetes提供了Service資源,Service會對提供同一個服務的多個pod進行聚合,并且提供一個統一的入口地址。通過訪問Service的入口地址就能訪問到后面的pod服務。 Service在很多情況下只是一個概念,真正起作用的其實是kube-proxy服務進程,每個Node節點上都運行著一個kube-proxy服務進程。當創建Service的時候會通過api-server向etcd寫入創建的service的信息,而kube-proxy會基于監聽的機制發現這種Service的變動,然后它會將最新的Service信息轉換成對應的訪問規則。

二、 Kube-proxy的三種模式

2.1 userspace 模式

userspace模式下,kube-proxy會為每一個Service創建一個監聽端口,發向Cluster IP的請求被Iptables規則重定向到kube-proxy監聽的端口上,kube-proxy根據LB(LoadBalance,負載均衡)算法選擇一個提供服務的Pod并和其建立鏈接,以將請求轉發到Pod上。 該模式下,kube-proxy充當了一個四層負載均衡器的角色。由于kube-proxy運行在userspace中,在進行轉發處理時會增加內核和用戶空間之間的數據拷貝,雖然比較穩定,但是效率比較低。

2.2 iptables 模式

iptables模式下,kube-proxy為service后端的每個Pod創建對應的iptables規則,直接將發向Cluster IP的請求重定向到一個Pod IP。 該模式下kube-proxy不承擔四層負載均衡器的角色,只負責創建iptables規則。該模式的優點是較userspace模式效率更高,但不能提供靈活的LB策略,當后端Pod不可用時也無法進行重試。

2.3 ipvs 模式

ipvs模式和iptables類似,kube-proxy監控Pod的變化并創建相應的ipvs規則。ipvs相對iptables轉發效率更高。除此以外,ipvs支持更多的LB算法。

# 此模式必須安裝ipvs內核模塊(集群部署的時候已安裝),否則會降級為iptables
# 開啟ipvs,cm: configmap
[root@k8s-master01 ~]# kubectl edit cm kube-proxy -n kube-system
# 修改mode: "ipvs"
[root@k8s-master01 ~]# kubectl delete pod -l k8s-app=kube-proxy -n kube-system
[root@node1 ~]# ipvsadm -Ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags-> RemoteAddress:Port ? ? ? ? ? Forward Weight ActiveConn InActConn
TCP ?172.16.32.128:30080 rr-> 172.16.79.79:80 ? ? ? ? ? ?  Masq ? ?1 ? ? ?0 ? ? ? ? ?0 ? ? ? ? 
TCP ?172.16.32.128:32665 rr-> 172.16.79.82:8443 ? ? ? ? ?  Masq ? ?1 ? ? ?0 ? ? ? ? ?0 ? ? ? ? 
TCP ?172.17.0.1:30080 rr-> 172.16.79.79:80 ? ? ? ? ? ?  Masq ? ?1 ? ? ?0 ? ? ? ? ?0 ? ? ? ? 
TCP ?172.17.0.1:32665 rr-> 172.16.79.82:8443 ? ? ? ? ?  Masq ? ?1 ? ? ?0 ? ? ? ? ?0 ? ? ? ? 
TCP ?192.168.115.161:30080 rr-> 172.16.79.79:80 ? ? ? ? ? ?  Masq ? ?1 ? ? ?0 ? ? ? ? ?0 ? ? ? ? 
TCP ?192.168.115.161:32665 rr-> 172.16.79.82:8443 ? ? ? ? ?  Masq ? ?1 ? ? ?0 ? ? ? ? ?0 ? ? ? ? 
TCP ?192.168.115.166:30080 rr-> 172.16.79.79:80 ? ? ? ? ? ?  Masq ? ?1 ? ? ?0 ? ? ? ? ?0 ? ? ? ? 
TCP ?192.168.115.166:32665 rr-> 172.16.79.82:8443 ? ? ? ? ?  Masq ? ?1 ? ? ?0 ? ? ? ? ?0 ? ? ? ? 
TCP ?10.10.0.1:443 rr-> 192.168.115.161:6443 ? ? ? ? Masq ? ?1 ? ? ?0 ? ? ? ? ?0 ? ? ? ? -> 192.168.115.162:6443 ? ? ? ? Masq ? ?1 ? ? ?0 ? ? ? ? ?0 ? ? ? ? -> 192.168.115.163:6443 ? ? ? ? Masq ? ?1 ? ? ?1 ? ? ? ? ?0 ? ? ? ? 
TCP ?10.10.0.10:53 rr-> 172.16.122.139:53 ? ? ? ? ?  Masq ? ?1 ? ? ?0 ? ? ? ? ?0 ? ? ? ? -> 172.16.122.140:53 ? ? ? ? ?  Masq ? ?1 ? ? ?0 ? ? ? ? ?0 ? ? ? ? 
TCP ?10.10.0.10:9153 rr-> 172.16.122.139:9153 ? ? ? ?  Masq ? ?1 ? ? ?0 ? ? ? ? ?0 ? ? ? ? -> 172.16.122.140:9153 ? ? ? ?  Masq ? ?1 ? ? ?0 ? ? ? ? ?0 ? ? ? ? 
TCP ?10.10.39.128:8000 rr-> 172.16.79.80:8000 ? ? ? ? ?  Masq ? ?1 ? ? ?0 ? ? ? ? ?0 ? ? ? ? 
TCP ?10.10.128.23:443 rr-> 172.16.79.81:443 ? ? ? ? ? ? Masq ? ?1 ? ? ?0 ? ? ? ? ?0 ? ? ? ? 
TCP ?10.10.166.16:8000 rr-> 172.16.79.79:80 ? ? ? ? ? ?  Masq ? ?1 ? ? ?0 ? ? ? ? ?0 ? ? ? ? 
TCP ?10.10.195.192:443 rr-> 172.16.79.82:8443 ? ? ? ? ?  Masq ? ?1 ? ? ?0 ? ? ? ? ?0 ? ? ? ? 
UDP ?10.10.0.10:53 rr-> 172.16.122.139:53 ? ? ? ? ?  Masq ? ?1 ? ? ?0 ? ? ? ? ?0 ? ? ? ? -> 172.16.122.140:53 ? ? ? ? ?  Masq ? ?1 ? ? ?0 ? ? ? ? ?0 ? ? ? 

三、Service資源類型

常見的Service資源清單

apiVersion: v1
kind: Service
matadata: ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?#元數據name: string ? ? ? ? ? ? ? ? ? ? ? ? ? #service的名稱namespace: string ? ? ? ? ? ? ? ? ? ? ?#命名空間 ?labels: ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?#自定義標簽屬性列表- name: stringannotations: ? ? ? ? ? ? ? ? ? ? ? ? ? #自定義注解屬性列表 ?- name: string
spec: ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?#詳細描述selector: [] ? ? ? ? ? ? ? ? ? ? ? ? ? #label selector配置,將選擇具有label標簽的Pod作為管理范圍type: string ? ? ? ? ? ? ? ? ? ? ? ? ? #service的類型,指定service的訪問方式,默認為clusterIp ? ? ? ? ? ? ?clusterIP: string ? ? ? ? ? ? ? ? ? ? ?#虛擬服務地址 ? ? ?sessionAffinity: string ? ? ? ? ? ? ? ?#是否支持sessionports: ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #service需要暴露的端口列表- name: string ? ? ? ? ? ? ? ? ? ? ? ? #端口名稱protocol: string ? ? ? ? ? ? ? ? ? ? #端口協議,支持TCP和UDP,默認TCPport: int ? ? ? ? ? ? ? ? ? ? ? ? ? ?#服務監聽的service端口號targetPort: int ? ? ? ? ? ? ? ? ? ? ?#需要轉發到后端Pod的端口號nodePort: int ? ? ? ? ? ? ? ? ? ? ? ?#當type = NodePort時,指定映射到物理機的端口號status: ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?#當spce.type=LoadBalancer時,設置外部負載均衡器的地址loadBalancer: ? ? ? ? ? ? ? ? ? ? ? ?#外部負載均衡器 ? ?ingress: ? ? ? ? ? ? ? ? ? ? ? ? ? #外部負載均衡器 ip: string ? ? ? ? ? ? ? ? ? ? ? #外部負載均衡器的Ip地址值hostname: string ? ? ? ? ? ? ? ? #外部負載均衡器的主機名

資源清單案例

apiVersion: v1 ?# 資源版本
kind: Service ?# 資源類型
metadata: # 元數據name: service # 資源名稱namespace: dev # 命名空間
spec: # 描述selector: # 標簽選擇器,用于確定當前service代理哪些podapp: nginxtype: # Service類型,指定service的訪問方式clusterIP: ?# 虛擬服務的ip地址sessionAffinity: # session親和性,支持ClientIP、None兩個選項ports: # 端口信息- protocol: TCP port: 3017 ?# service端口targetPort: 5003 # pod端口nodePort: 31122 # 主機端口

Service中的service.spec.type類型

類型含義
ClusterIP意味著服務僅在集群內部可用,只能通過集群IP訪問。
ExternalName意味著服務僅包含一個對外部名稱的引用,Kubedns或等價物將返回作為CNAME記錄,不會涉及任何容器的暴露或代理。
LoadBalancer意味著服務將通過外部負載均衡器(如果云提供商支持的話)進行暴露,除了NodePort類型之外。
NodePort意味著服務將在每個節點的一個端口上進行暴露,除了ClusterIP類型之外。

Service中的三類IP地址

IP類型作用
Node IP節點IP是Kubernetes集群中每個節點的唯一標識符。它代表了節點的網絡接口,用于在集群內部進行通信。節點IP通常是一個私有IP地址范圍,用于在集群內部進行通信。節點IP是Service在集群內部提供服務的唯一標識,用于路由流量到指定的Pod。
Pod IPPod IP是Kubernetes中每個Pod的唯一標識符。它代表了Pod的網絡接口,用于在集群內部進行通信。Pod IP通常是一個私有IP地址范圍,用于在集群內部進行通信。Pod IP是Service在集群內部提供服務的唯一標識,用于路由流量到指定的Pod。
Cluster IPCluster IP是Kubernetes集群中Service的IP地址。它代表了Service在集群內部提供的服務,用于在集群內部進行通信。Cluster IP通常是一個私有IP地址范圍,用于在集群內部進行通信。Cluster IP是Service在集群內部提供服務的唯一標識,用于路由流量到指定的Pod。

綜上所述,Kubernetes中的三類IP地址分別是Node IP、Pod IP和Cluster IP。這些IP地址用于在不同網絡之間路由流量,以便外部和內部應用程序可以訪問Kubernetes集群中的服務和Pod。

四、Service實戰案例

實驗環境準備

在使用service之前,首先利用Deployment創建出3個pod,注意要為pod設置app=nginx-pod的標簽

創建deployment.yaml,內容如下:

apiVersion: apps/v1
kind: Deployment ? ? ?
metadata:name: pc-deploymentnamespace: dev
spec: replicas: 3selector:matchLabels:app: nginx-podtemplate:metadata:labels:app: nginx-podspec:containers:- name: nginximage: nginxports:- containerPort: 80
[root@k8s-master01 ~]# kubectl create -f deployment.yaml
deployment.apps/pc-deployment created
?
# 查看pod詳情
[root@k8s-master01 ~]# kubectl get pods -n dev -o wide --show-labels
NAME ? ? ? ? ? ? ? ? ? ? ? ? ? ? READY ? STATUS ?  RESTARTS ? AGE ? IP ? ? ? ? ? ?  NODE ? ? ? ? ? NOMINATED NODE ? READINESS GATES ? LABELS
pc-deployment-59c564ffb7-8vzp5 ? 1/1 ? ? Running ? 0 ? ? ? ?  89s ? 172.16.79.83 ?  k8s-worker01 ? <none> ? ? ? ? ? <none> ? ? ? ? ? ?app=nginx-pod,pod-template-hash=59c564ffb7
pc-deployment-59c564ffb7-fg2j8 ? 1/1 ? ? Running ? 0 ? ? ? ?  89s ? 172.16.69.206 ? k8s-worker02 ? <none> ? ? ? ? ? <none> ? ? ? ? ? ?app=nginx-pod,pod-template-hash=59c564ffb7
pc-deployment-59c564ffb7-sprp7 ? 1/1 ? ? Running ? 0 ? ? ? ?  89s ? 172.16.69.207 ? k8s-worker02 ? <none> ? ? ? ? ? <none> ? ? ? ? ? ?app=nginx-pod,pod-template-hash=59c564ffb7
?
# 為了方便后面的測試,修改下三臺nginx的index.html頁面(三臺修改的IP地址不一致)
[root@k8s-master01 ~]# kubectl exec -it pc-deployment-59c564ffb7-8vzp5 -n dev -- /bin/sh
root@pc-deployment-59c564ffb7-8vzp5:/# echo "172.16.79.83" > /usr/share/nginx/html/index.html 
[root@k8s-master01 ~]# kubectl -n dev exec -it pc-deployment-59c564ffb7-fg2j8 -- /bin/bash
root@pc-deployment-59c564ffb7-fg2j8:/# echo "172.16.69.206" > /usr/share/nginx/html/index.html
[root@k8s-master01 ~]# kubectl -n dev exec -it pc-deployment-59c564ffb7-sprp7 -- /bin/bash
root@pc-deployment-59c564ffb7-sprp7:/# echo "172.16.69.207" > /usr/share/nginx/html/index.html 
#修改完畢之后,訪問測試
[root@k8s-master01 ~]# curl 172.16.79.83
172.16.79.83
[root@k8s-master01 ~]# curl 172.16.69.206
172.16.69.206
[root@k8s-master01 ~]# curl 172.16.69.207
172.16.69.207

4.1 ClusterIP類型的Service

創建service-clusterip.yaml文件apiVersion: v1
kind: Service
metadata:name: service-clusteripnamespace: dev
spec:selector:app: nginx-podclusterIP: 10.10.97.97 # service的ip地址,如果不寫,默認會生成一個type: ClusterIPports:- port: 80 ?# Service端口 ? ? ? targetPort: 80 # pod端口# 創建service
[root@k8s-master01 ~]# kubectl create -f service-clusterip.yaml
service/service-clusterip created
?
# 查看service
[root@k8s-master01 ~]# kubectl get svc -n dev 
[root@k8s-master01 ~]# kubectl -n dev get svc
NAME ? ? ? ? ? ? ?  TYPE ? ? ?  CLUSTER-IP ?  EXTERNAL-IP ? PORT(S) ?  AGE
service-clusterip ? ClusterIP ? 10.10.97.97 ? <none> ? ? ? ?8001/TCP ? 10s
?
# 查看service的詳細信息
# 在這里有一個Endpoints列表,里面就是當前service可以負載到的服務入口
[root@k8s-master01 ~]# kubectl describe service -n dev
Name: ? ? ? ? ? ?  service-clusterip
Namespace: ? ? ? ? dev
Labels: ? ? ? ? ?  <none>
Annotations: ? ? ? <none>
Selector: ? ? ? ? ?app=nginx-pod
Type: ? ? ? ? ? ?  ClusterIP
IP Family Policy:  SingleStack
IP Families: ? ? ? IPv4
IP: ? ? ? ? ? ? ? ?10.10.97.97
IPs: ? ? ? ? ? ? ? 10.10.97.97
Port: ? ? ? ? ? ?  <unset> ?8001/TCP
TargetPort: ? ? ? ?80/TCP
Endpoints: ? ? ? ? 172.16.69.206:80,172.16.69.207:80,172.16.79.83:80
Session Affinity:  None
Events: ? ? ? ? ?  <none>
?
# 查看ipvs的映射規則
[root@k8s-master01 ~]# ipvsadm -Ln
TCP ?10.97.97.97:80 rr-> 10.10.1.39:80 ? ? ? ? ? ? ? Masq ? ?1 ? ? ?0 ? ? ? ? ?0-> 10.10.1.40:80 ? ? ? ? ? ? ? Masq ? ?1 ? ? ?0 ? ? ? ? ?0-> 10.10.2.33:80 ? ? ? ? ? ? ? Masq ? ?1 ? ? ?0 ? ? ? ? ?0
?
# 訪問10.10.97.97:8001觀察效果
?
[root@k8s-master01 ~]# curl 10.10.97.97:8001
172.16.79.83
[root@k8s-master01 ~]# curl 10.10.97.97:8001
172.16.69.207
[root@k8s-master01 ~]# curl 10.10.97.97:8001
172.16.69.206

Endpoint解析

  • Endpoint是kubernetes中的一個資源對象,存儲在etcd中,用來記錄一個service對應的所有pod的訪問地址,它是根據service配置文件中selector描述產生的。

  • 一個Service由一組Pod組成,這些Pod通過Endpoints暴露出來,Endpoints是實現實際服務的端點集合。換句話說,service和pod之間的聯系是通過endpoints實現的。

負載分發策略

對Service的訪問被分發到了后端的Pod上去,目前kubernetes提供了兩種負載分發策略:

  • 如果不定義,默認使用kube-proxy的策略,比如隨機、輪詢

  • 基于客戶端地址的會話保持模式,即來自同一個客戶端發起的所有請求都會轉發到固定的一個Pod上

# 查看ipvs的映射規則【rr 輪詢】
[root@k8s-master01 ~]# ipvsadm -Ln
TCP ?10.97.97.97:80 rr-> 10.10.1.39:80 ? ? ? ? ? ? ? Masq ? ?1 ? ? ?0 ? ? ? ? ?0-> 10.10.1.40:80 ? ? ? ? ? ? ? Masq ? ?1 ? ? ?0 ? ? ? ? ?0-> 10.10.2.33:80 ? ? ? ? ? ? ? Masq ? ?1 ? ? ?0 ? ? ? ? ?0
?
# 循環訪問測試
[root@k8s-master01 ~]# while true;do curl 10.97.97.97:80; sleep 5;  done;
10.10.1.40
10.10.1.39
10.10.2.33
10.10.1.40
10.10.1.39
10.10.2.33
?
# 修改分發策略----sessionAffinity:ClientIP
?
# 查看ipvs規則【persistent 代表持久】
[root@k8s-master01 ~]# ipvsadm -Ln
TCP ?10.97.97.97:80 rr persistent 10800-> 10.10.1.39:80 ? ? ? ? ? ? ? Masq ? ?1 ? ? ?0 ? ? ? ? ?0-> 10.10.1.40:80 ? ? ? ? ? ? ? Masq ? ?1 ? ? ?0 ? ? ? ? ?0-> 10.10.2.33:80 ? ? ? ? ? ? ? Masq ? ?1 ? ? ?0 ? ? ? ? ?0
?
# 循環訪問測試
[root@k8s-master01 ~]# while true;do curl 10.97.97.97; sleep 5; done;
10.10.2.33
10.10.2.33
10.10.2.33# 刪除service
[root@k8s-master01 ~]# kubectl delete -f service-clusterip.yaml
service "service-clusterip" deleted
[root@k8s-master01 ~]# kubectl delete service service-clusterip -n dev
service "service-clusterip" deleted

4.2 HeadLiness類型的Service

在某些場景中,開發人員可能不想使用Service提供的負載均衡功能,而希望自己來控制負載均衡策略,針對這種情況,kubernetes提供了HeadLiness Service,這類Service不會分配Cluster IP,如果想要訪問service,只能通過service的域名進行查詢。

創建service-headliness.yaml

apiVersion: v1
kind: Service
metadata:name: service-headlinessnamespace: dev
spec:selector:app: nginx-podclusterIP: None # 將clusterIP設置為None,即可創建headliness Servicetype: ClusterIPports:- port: 80 ? ?targetPort: 80
?# 創建service
[root@k8s-master01 ~]# kubectl apply -f deployment-nginx-headliness.yaml
service/service-headliness created
?
# 獲取service, 發現CLUSTER-IP未分配
[root@k8s-master01 ~]# kubectl -n dev get svc
NAME ? ? ? ? ? ? ? ? TYPE ? ? ?  CLUSTER-IP ? EXTERNAL-IP ? PORT(S) ? AGE
service-headliness ? ClusterIP ? None ? ? ? ? <none> ? ? ? ?80/TCP ?  10s
?
# 查看service詳情
[root@k8s-master01 ~]# kubectl describe svc -n dev
Name: ? ? ? ? ? ?  service-headliness
Namespace: ? ? ? ? dev
Labels: ? ? ? ? ?  <none>
Annotations: ? ? ? <none>
Selector: ? ? ? ? ?app=nginx-pod
Type: ? ? ? ? ? ?  ClusterIP
IP Family Policy:  SingleStack
IP Families: ? ? ? IPv4
IP: ? ? ? ? ? ? ?  None
IPs: ? ? ? ? ? ? ? None
Port: ? ? ? ? ? ?  <unset> ?80/TCP
TargetPort: ? ? ? ?80/TCP
Endpoints: ? ? ? ? 172.16.69.206:80,172.16.69.207:80,172.16.79.83:80
Session Affinity:  None
Events: ? ? ? ? ?  <none>
?
?
# 查看域名的解析情況
[root@k8s-master01 ~]# kubectl  -n dev exec -it pc-deployment-59c564ffb7-8vzp5 -- /bin/bash 
[root@k8s-master01 ~]# kubectl  -n dev exec -it pc-deployment-59c564ffb7-8vzp5 -- /bin/bash 
root@pc-deployment-59c564ffb7-8vzp5:/#
root@pc-deployment-59c564ffb7-8vzp5:/# cat /etc/resolv.conf 
search dev.svc.cluster.local svc.cluster.local cluster.local
nameserver 10.10.0.10
options ndots:5
?
[root@k8s-master01 ~]# dig @10.96.0.10 service-headliness.dev.svc.cluster.local
service-headliness.dev.svc.cluster.local. 30 IN A 172.16.79.83
service-headliness.dev.svc.cluster.local. 30 IN A 172.16.69.206
service-headliness.dev.svc.cluster.local. 30 IN A 172.16.69.207
?
#刪除service
[root@k8s-master01 ~]# kubectl delete -n dev svc service-headliness
service "service-headliness" deleted

4.3 NodePort類型的Service

在之前的樣例中,創建的Service的ip地址只有集群內部才可以訪問,如果希望將Service暴露給集群外部使用,那么就要使用到另外一種類型的Service,稱為NodePort類型。NodePort的工作原理其實就是將service的端口映射到Node的一個端口上,然后就可以通過NodeIp:NodePort來訪問service了。

創建service-nodeport.yaml

apiVersion: v1
kind: Service
metadata:name: service-nodeportnamespace: dev
spec:selector:app: nginx-podtype: NodePort # service類型ports:- port: 80nodePort: 30002 # 指定綁定的node的端口(默認的取值范圍是:30000-32767), 如果不指定,會默認分配targetPort: 80# 創建service
[root@k8s-master01 ~]# kubectl apply -f deployment-nginx-nodeport.yaml 
service/service-nodeport created
?
?
# 查看service
[root@k8s-master01 ~]# kubectl -n dev get svc -o wide 
NAME ? ? ? ? ? ? ? TYPE ? ? ? CLUSTER-IP ? ? EXTERNAL-IP ? PORT(S) ? ? ?  AGE ? SELECTOR
service-nodeport ? NodePort ? 10.10.25.194 ? <none> ? ? ? ?80:30002/TCP ? 29s ? app=nginx-pod
?
# 接下來可以通過電腦主機的瀏覽器去訪問集群中任意一個nodeip的30002端口,即可訪問到pod
#刪除service
[root@k8s-master01 ~]# kubectl delete -n dev svc service-nodeport 
service "service-nodeport" deleted

4.4 LoadBalancer類型的Service

LoadBalancer和NodePort很相似,目的都是向外部暴露一個端口,區別在于LoadBalancer會在集群的外部再來做一個負載均衡設備,而這個設備需要外部環境支持的,外部服務發送到這個設備上的請求,會被設備負載之后轉發到集群中。

4.5 ExternalName類型的Service

ExternalName類型的Service用于引入集群外部的服務,它通過externalName屬性指定外部一個服務的地址,然后在集群內部訪問此service就可以訪問到外部的服務了。

創建service-externalname.yaml

apiVersion: v1
kind: Service
metadata:name: service-externalname
spec:type: ExternalName # service類型externalName: www.baidu.com ?# 創建service
[root@k8s-master01 ~]# kubectl apply -f deployment-nginx-externalname.yaml
service/service-externalname created
[root@k8s-master01 ~]# kubectl -n dev get svc -o wide 
NAME ? ? ? ? ? ? ? ? ? TYPE ? ? ? ? ? CLUSTER-IP ? EXTERNAL-IP ? ? PORT(S) ? AGE ? SELECTOR
service-externalname ? ExternalName ? <none> ? ? ? www.baidu.com ? <none> ?  7s ?  <none>
[root@k8s-master01 ~]# kubectl describe -n dev svc
Name: ? ? ? ? ? ?  service-externalname
Namespace: ? ? ? ? dev
Labels: ? ? ? ? ?  <none>
Annotations: ? ? ? <none>
Selector: ? ? ? ?  <none>
Type: ? ? ? ? ? ?  ExternalName
IP Families: ? ? ? <none>
IP: ? ? ? ? ? ? ? ?
IPs: ? ? ? ? ? ? ? <none>
External Name: ? ? www.baidu.com
Session Affinity:  None
Events: ? ? ? ? ?  <none>
?
# 域名解析
[root@k8s-master01 ~]# dig @10.10.0.10 service-externalname.dev.svc.cluster.local
?
; <<>> DiG 9.11.4-P2-RedHat-9.11.4-26.P2.el7_9.15 <<>> @10.10.0.10 service-externalname.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: 33580
;; flags: qr aa rd; QUERY: 1, ANSWER: 4, AUTHORITY: 0, ADDITIONAL: 1
;; WARNING: recursion requested but not available
?
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;service-externalname.dev.svc.cluster.local. IN A
?
;; ANSWER SECTION:
service-externalname.dev.svc.cluster.local. 5 IN CNAME www.baidu.com.
www.baidu.com.      5   IN  CNAME   www.a.shifen.com.
www.a.shifen.com.   5   IN  A   39.156.66.18
www.a.shifen.com.   5   IN  A   39.156.66.14
?
;; Query time: 127 msec
;; SERVER: 10.10.0.10#53(10.10.0.10)
;; WHEN: 四 1月 25 15:04:37 CST 2024
;; MSG SIZE  rcvd: 247

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/pingmian/93548.shtml
繁體地址,請注明出處:http://hk.pswp.cn/pingmian/93548.shtml
英文地址,請注明出處:http://en.pswp.cn/pingmian/93548.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

GaussDB常用術語縮寫及釋義

序號 術語全稱釋義1ACLAccess Control List訪問控制列表&#xff0c;被授權訪問某一資源的實體及其訪問權限的列表。2APIApplication Programming Interface應用程序接口&#xff0c;一些預先定義的接口&#xff08;如函數&#xff0c;http接口&#xff09;或指軟件系統不同組…

工業一體機5G通訊IC/ID刷卡讓MES系統管理更智能

在智能制造升級過程中&#xff0c;MES 系統作為生產執行的核心樞紐&#xff0c;其數據采集的實時性、準確性與管理安全性直接決定管理效能。傳統 MES 系統常面臨數據傳輸滯后、設備對接繁瑣、權限管理粗放等問題&#xff0c;而工業一體機憑借 5G 通訊與 IC/ID 刷卡功能&#xf…

電腦開機幾秒后就停止然后再循環是怎么回事

硬件問題電源問題&#xff1a;電源內部的濾波電容若出現鼓包或漏液現象&#xff0c;會導致電源供電不足&#xff0c;從而使電腦開機后自動停止并重新啟動。另外&#xff0c;電源線連接不良、插座無電或電源供應器故障&#xff0c;也可能引發此問題。CPU 散熱問題&#xff1a;如…

OSCP - Proving Grounds - Vanity

主要知識點Linux命令注入rsync 腳本劫持(以前tar 備份腳本劫持也是利用了類似的方法&#xff09;具體步驟nmap掃描結果&#xff0c;發現web服務開放&#xff0c;并且 rsync服務開放&#xff0c;值得研究一下Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-10-30 14:37 UT…

詳細探討AI在金融、醫療、教育和制造業四大領域的具體落地案例,并通過代碼、流程圖、Prompt示例和圖表等方式展示這些應用的實際效果。

1. 引言&#xff1a;AI技術概述及其在各行業的重要性人工智能(AI)技術近年來取得了突破性進展&#xff0c;從理論研究走向了廣泛的商業應用。AI的核心技術包括機器學習、深度學習、自然語言處理、計算機視覺等&#xff0c;這些技術正在深刻改變各行各業的運營模式和服務方式。在…

我的第一個開源項目:從0到1,我在GitHub寫下的成長印記

文章目錄每日一句正能量前言? 一、寫在前面&#xff1a;那天我點下了 “Create Repository”&#x1f680; 二、為什么我要做這件事&#xff1f;&#x1f6e0;? 三、CommonUtilLibrary 是什么&#xff1f;? 四、第一次 Star 和第一次 Issue&#x1f9ed; 五、我從中學到了什…

數據結構(03)——線性表(順序存儲和鏈式存儲)

Hi&#xff01;探索者們&#x1f609;&#xff0c;歡迎踏入 408 數據結構的奇妙秘境&#x1f33f;&#xff01;? 我是 ankleless&#x1f4da;&#xff0c;和你并肩的尋寶人&#xff5e; 這是我的探險手札&#x1f5fa;?&#xff0c;里面記著鏈表森林的岔路陷阱&#x1f578;…

bun + vite7 的結合,孕育的 Robot Admin 【靚仔出道】(十三)

主題定制 &#x1f4d6; 閱讀時間&#xff1a;7 分鐘 | &#x1f3af; 等級&#xff1a;進階 前言 Robot_Admin應用程序具有靈活的主題系統&#xff0c;支持淺色、深色和基于系統的模式&#xff0c;以及程序化的主題定制。本指南介紹了如何在開發工作中使用和擴展主題功能。 …

檢測pytorch是否安裝好

如果pytorch安裝成功即可導入。import torch查看cuda是否可用&#xff0c;可用的話返回“ture”。print(torch.cuda.is_available())查看可用的cuda數量。print(torch.cuda.device_count())查看cuda的版本號。print(torch.version.cuda)

java八股文-(spring cloud)微服務篇-參考回答

一. 面試官&#xff1a;Spring Cloud 5大組件有哪些&#xff1f;Spring Cloud 的五大核心組件包括&#xff1a;注冊中心&#xff1a;第一代使用 Eureka&#xff0c;第二代使用 Nacos。負載均衡&#xff1a;第一代使用 Ribbon&#xff0c;第二代使用 Spring Cloud LoadBalancer。…

發布npmjs組件庫

一.初始化項目1.用Vite創建空項目2.安裝打包與聲明文件插件pnpm i -D vite-plugin-dts sass二.首先修改項目內容// src\index.ts import { type App } from vue; import oneComponent from "./components/oneComponent/index.vue"; import twoComponent from ".…

【C語言16天強化訓練】從基礎入門到進階:Day 2

&#x1f525;個人主頁&#xff1a;艾莉絲努力練劍 ?專欄傳送門&#xff1a;《C語言》、《數據結構與算法》、C語言刷題12天IO強訓、LeetCode代碼強化刷題、洛谷刷題、C/C基礎知識知識強化補充、C/C干貨分享&學習過程記錄 &#x1f349;學習方向&#xff1a;C/C方向 ??人…

【學習筆記】面向AI安全的26個緩解措施

一、Mitre Atlas矩陣概述 ATLAS 矩陣從左到右以列形式顯示了攻擊中使用的策略的進展&#xff0c;ML 技術屬于上面的每種策略。& 表示從 ATT&CK 改編而來。 詳見&#xff1a;ATLAS Matrix | MITRE ATLAS? 注&#xff1a;機翻的效果不是太好&#xff0c;對照理解用吧。 …

AI出題人給出的Java后端面經(十八)(日更)

鏈接雙端鏈表 前一篇&#xff1a;AI出題人給出的Java后端面經&#xff08;十七&#xff09;&#xff08;日更&#xff09; 后一篇&#xff1a;null 目錄 &#x1f535; 一、Java基礎&#xff08;Java 17&#xff09; 答案&#xff1a; &#x1f5c3;? 二、持久化層&…

【音視頻】瑞芯微、全志芯片在運動相機和行車記錄儀產品分析

文章目錄開頭總結詳細分析**1. 瑞芯微芯片的典型型號及特性****2. 運動相機場景的適用性****優勢****劣勢****3. 行車記錄儀場景的適用性****優勢****劣勢****4. 與競品芯片對比****5. 推薦方案選擇****總結****1. 全志芯片的典型型號及特性****2. 運動相機場景的適用性****優勢…

《清華級防護,了解一下?》

前言講到滲透&#xff0c;我們不可避免會遇到有waf攔截咱們的攻擊許多朋友在滲透測試中因為遇到WAF而束手無策&#xff0c;實際上所謂的BYPASS WAF實際上是去尋找位于WAF設備之后處理應用層數據包的硬件/軟件的特性。利用特性構造WAF不能命中&#xff0c;但是在應用程序能夠執行…

CANDB++中的CAN_DBC快速編輯方法,使用文本編輯器(如notepad++和VScode)

前言:在做工程機械CAN協議相關的軟件開發與調試時&#xff0c;經常接觸到DBC的使用&#xff0c;可以在CAN分析儀中加載DBC文件從而快速查看某條CAN報文或信號的含義&#xff0c;以及使用圖形化的調試。而編輯DBC文件&#xff0c;正常是用CANDB來一條條添加&#xff0c;比較費時…

Tmux Xftp及Xshell的服務器使用方法

Tmux&#xff1a; Tmux是什么&#xff1a; 會話與進程&#xff1a; 命令行的典型使用方式是&#xff0c;打開一個終端窗口&#xff0c;在里面輸入命令。用戶與計算機的這種臨時的交互&#xff0c;稱為一次“會話”&#xff08;session&#xff09;。 會話的一個重要特點是&…

微服務遠程調用完全透傳實現:響應式與非響應式解決方案

&#x1f9d1; 博主簡介&#xff1a;CSDN博客專家&#xff0c;歷代文學網&#xff08;PC端可以訪問&#xff1a;https://literature.sinhy.com/#/?__c1000&#xff0c;移動端可微信小程序搜索“歷代文學”&#xff09;總架構師&#xff0c;15年工作經驗&#xff0c;精通Java編…

Kotlin集合概述

Kotlin 的集合類同樣由兩個接口派生&#xff1a; Collection 和 Map&#xff0c; Collection 和 Map 是 Java 集合框架的根接口&#xff0c;這兩個接口又包含了 一些子接口或實現類Kotlin 集合與 Java 集合不同&#xff0c; Java 集合都是可變集合一一開發者可以向集合中添加、…