2 篇文章带有标签 “Service”

Kubernetes中的Service

创建 Deployment 对象

$ kubectl apply -f kubia.yaml 
deployment.apps/kubia created
  • 使用 YAML 文件
apiVersion: v1
kind: Service
metadata:
  name: kubia
  labels:
    app: kubia
spec:
  ports:
  - port: 80
    targetPort: 8080
  selector:
    app: kubia

创建 Service 对象

$ kubectl apply -f kubia-service.yaml 
service/kubia created
  • 使用命令 kubectl expose
$ kubectl expose deployment kubia --name=kubia-http
service/kubia-http exposed

查看服务

$ kubectl get svc
NAME         TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)   AGE
kubia        ClusterIP   10.109.180.140   <none>        80/TCP    11m
kubia-http   ClusterIP   10.101.40.142    <none>        80/TCP    9m57s

svc 是 Service 的缩写