--- title: Service # 簡報的名稱 tags: K8s # 簡報的標籤 --- # Service > [name=李俊毅] > [time=Wed, Feb 5, 2020 1:02 PM] --- ## Agenda * 介紹 * 範例 * 常用的CLI --- ## 介紹 Service用於將一個Pod顯示為一個服務,在kubernetes中,Pod的IP地址會因Pod的重啟而變化,並不建議直接拿Pod的IP使用。 Service為一組Pod提供一個統一的入口,並為它們提供負載均衡和自動服務發現。 --- ## 範例 ---- hello-world-service.yaml ``` apiVersion: v1 kind: Service metadata: name: hello-world spec: selector: app.kubernetes.io/name: load-balancer-example ports: - port: 8080 targetPort: 8080 ``` --- ## 常用的CLI ---- ### 查詢 services ---- ``` kubectl get svc ``` ![](https://i.imgur.com/9fOYBxy.png)