k8s 无头service 是指 clusterIP 为 None 的service

案例,假定有一个 deployment,containerPort 端口80,同时还被打上 python=myweb 标签。
deployment内容如下

apiVersion: apps/v1
kind: Deployment
metadata:
  name: mywebdeployment
spec:
  selector:
    matchLabels:
      python: myweb
  replicas: 6
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 0
      maxUnavailable: 1
  template:
    metadata:
     labels:
       python: myweb
    spec:
      containers:
      - name: mywebcontainer
        image: python:3.7
        command: ['sh', '-c']
        args: ['echo "<p>The host is $(hostname) </p>" > index.html;python -m http.server 80']
        ports:
        - name: mywebport
          containerPort: 80

无头service如下

apiVersion: v1
kind: Service
metadata:
  name: myweb-service
spec:
  selector:
    python: myweb
  type: ClusterIP
  clusterIP: None
  ports:
  - port: 81
    targetPort: 80

创建工具型pod

apiVersion: v1
kind: Pod
metadata:
  name: mytestpod
  labels:
    pod: test
spec:
  containers:
  - name: mytestpod
    image: appropriate/curl
    command: ['sh','-c']
    args: ['echo "good";sleep 3600;']

进入工具型Pod,并且在pod中查询service的解析地址 {ServiceName}.{Namespace}.svc.{ClusterDomain}
k8s 无头service 方式向内发布

相关文章:

  • 2021-06-28
  • 2022-01-08
  • 2022-02-22
  • 2022-12-23
  • 2021-11-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-17
猜你喜欢
  • 2022-02-09
  • 2021-11-10
  • 2022-12-23
  • 2021-12-12
  • 2021-08-08
  • 2021-12-14
  • 2022-01-13
相关资源
相似解决方案