kubernetes 简单service的例子

首先建一个Deployment:

apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: httpd
spec:
  replicas: 3
  template:
    metadata:
      labels:       #设置一个标签 以下创建service的时候将使用这个标签
        run: httpd
      spec:
        containers:
        - name: httpd
          image: httpd
          ports:
          - containerPort: 80

创建service:

apiVersion: v1   #v1是Service的 apiVersion
kind: Service     #类型为Service
metadata:          
  name: httpd-svc  #service名字为 httpd-svc
spec:
  selector:    #指明挑选label标签为 run:httpd 的pod作为service的后端
    run: httpd
  ports:         #将service的8080端口映射到pod的80端口, 使用tcp协议
  - protocol: TCP
    port: 8080
    targetPort: 80

  

查看service:

kubectl  get  service  

kubectl  describe  service httpd

猜你喜欢

转载自www.cnblogs.com/kuku0223/p/9183716.html