ZBLOG

k8s service yml

Here is an example of a Kubernetes Service YAML file:

apiVersion: v1
kind: Service
metadata:
  name: my-service
spec:
  selector:
    app: my-app
  ports:
    - name: http
      protocol: TCP
      port: 80
      targetPort: 8080
  type: ClusterIP

Let’s break down the different sections of this YAML file:

  • apiVersion: This specifies the API version that the Service object is using.
  • kind: This tells Kubernetes what kind of object we’re creating, in this case a Service.
  • metadata: This section provides information about the Service, such as its name.
  • spec: This section defines the specification for the Service.
  • selector: This specifies which Pods the Service should target. In this case, it targets any Pod with the label app: my-app.
  • ports: This section defines the ports that the Service will listen on and forward traffic to. In this case, it listens on port 80 and forwards traffic to port 8080 on the target Pods.
  • type: This specifies the type of Service. ClusterIP creates a virtual IP address within the cluster that other services can use to access the Service.

This Service YAML file creates a Service named my-service that targets Pods with the label app: my-app. It listens on port 80 and forwards traffic to port 8080 on the target Pods. The Service is of type ClusterIP, meaning it creates a virtual IP address that other services can use to access it within the cluster.

本站部分文章来源于网络,版权归原作者所有,如有侵权请联系站长删除。
转载请注明出处:https://golang.0voice.com/?id=2338

分享:
扫描分享到社交APP
上一篇
下一篇
发表列表
游客 游客
此处应有掌声~
评论列表

还没有评论,快来说点什么吧~

联系我们

在线咨询: 点击这里给我发消息

微信号:3007537140

上班时间: 10:30-22:30

关注我们
x

注册

已经有帐号?