k8s之StatefulSet绑定headlessService实现域名解析

一 StatefulSet

demo

apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: web
  namespace:
spec:
  selector:
    matchLabels:
      app: nginx #必须匹配 .spec.template.metadata.labels
  serviceName: "nginx"  #声明它属于哪个Headless Service.
  replicas:  1 #副本数
  template:
    metadata:
      labels:
        app: nginx # 必须配置 .spec.selector.matchLabels
    spec:
      terminationGracePeriodSeconds: 10
      containers:
      - name: nginx
        image: nginx:latest
        ports:
        - containerPort: 80
          name: web

二 HeadlessService

demo

apiVersion: v1
kind: Service
metadata:
  name: nginx
  labels:
    app: nginx
spec:
  ports:
  - port: 80
    name: web
  clusterIP: None
  selector:
    app: nginx

三 测试

进入容器

kubectl exec web-0 -it bash

使用curl(不能用ping)

curl http://nginx.default

成功
k8s之StatefulSet绑定headlessService实现域名解析_第1张图片

你可能感兴趣的:(nginx,linux,https)