網站首頁 編程語言 正文
Service 引入主要是解決 Pod 的動態變化,提供統一訪問入口:
- 防止 Pod 失聯,準備找到提供同一個服務的 Pod (服務發現)?
- 定義一組 Pod 的訪問策略 (負載均衡)
部署 deploy
kubectl apply -f deploy.yaml
apiVersion: apps/v1 kind: Deployment metadata: name: chiyi-nginx spec: replicas: 3 selector: matchLabels: app: chiyi-nginx template: metadata: labels: app: chiyi-nginx spec: containers: - name: nginx image: nginx:1.14.2 ports: - containerPort: 80
部署 service
kubectl apply -f service.yaml
apiVersion: v1 kind: Service metadata: name: chiyi-nginx spec: selector: app: chiyi-nginx ports: - protocol: TCP port: 80 targetPort: 80 nodePort: 30002 type: NodePort
查看 service 和 pod 的關系
kubectl get ep curl 10.244.1.58:80
說明:
Service 通過標簽關聯一組 Pod
Service 為一組 Pod 提供負載均衡能力
[root@k8s-master service]# kubectl get ep NAME ENDPOINTS AGE chiyi-nginx 10.244.1.58:80,10.244.1.59:80,10.244.2.46:80 5m19s kubernetes 172.17.28.225:6443 23h [root@k8s-master service]# curl 10.244.1.58:80 <!DOCTYPE html> <html> <head> <title>Welcome to nginx!</title> <style> body { width: 35em; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif; } </style> </head> <body> <h1>Welcome to nginx!</h1> <p>If you see this page, the nginx web server is successfully installed and working. Further configuration is required.</p> <p>For online documentation and support please refer to <a >nginx.org</a>.<br/> Commercial support is available at <a >nginx.com</a>.</p> <p><em>Thank you for using nginx.</em></p> </body> </html>
查看 service
kubectl get service curl 10.101.104.218
[root@k8s-master service]# kubectl get service NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE chiyi-nginx NodePort 10.101.104.218 <none> 80:30002/TCP 6m3s kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 23h [root@k8s-master service]# curl 10.101.104.218 <!DOCTYPE html> <html> <head> <title>Welcome to nginx!</title> <style> body { width: 35em; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif; } </style> </head> <body> <h1>Welcome to nginx!</h1> <p>If you see this page, the nginx web server is successfully installed and working. Further configuration is required.</p> <p>For online documentation and support please refer to <a >nginx.org</a>.<br/> Commercial support is available at <a >nginx.com</a>.</p> <p><em>Thank you for using nginx.</em></p> </body> </html>
查看端口
ss -antp |grep 30002
[root@k8s-master service]# ss -antp |grep 30002 LISTEN 0 128 *:30002 *:* users:(("kube-proxy",pid=3544,fd=13))
導出 yaml
kubectl get service chiyi-nginx -o yaml
篩選 service 關聯 pod
kubectl get pods -l app=chiyi-nginx
[root@k8s-master service]# kubectl get pods -l app=chiyi-nginx NAME READY STATUS RESTARTS AGE chiyi-nginx-5bbf8bff4b-6bwfz 1/1 Running 0 3m58s chiyi-nginx-5bbf8bff4b-bpvvc 1/1 Running 0 3m58s chiyi-nginx-5bbf8bff4b-pwwt4 1/1 Running 0 3m58s
擴容測試
kubectl scale deployment chiyi-nginx --replicas=1 kubectl get service,pods,ep
Service 三種常用類型
- ClusterIP 集群內部使用,任一節點服務器和 pod 內部都可以訪問
- NodePort 對外暴露應用(端口默認范圍:30000-32767),任一節點服務器公網IP+端口號,可在瀏覽器訪問。
- LoadBalancer 對外暴露應用,適合公有云
原文鏈接:https://blog.csdn.net/smile_tianya/article/details/123775454
相關推薦
- 2022-07-16 ssh遠程連接docker
- 2023-02-15 C#?9使用foreach擴展的示例詳解_C#教程
- 2022-08-15 Python自制隨機數生成算法
- 2022-04-15 C#的并發機制優秀在哪你知道么_C#教程
- 2023-06-13 react實現組件狀態緩存的示例代碼_React
- 2022-12-09 C/C++中時間庫函數的使用詳解_C 語言
- 2022-06-29 Oracle中的分析函數匯總_oracle
- 2023-01-02 Kotlin類對象class初始化與使用_Android
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支