k8s 無頭service 方式向內發布


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}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM