集群部署yaml
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
annotations: {}
labels:
name: cloud-consul
name: cloud-consul
namespace: default
spec:
podManagementPolicy: OrderedReady
replicas: 3
revisionHistoryLimit: 10
selector:
matchLabels:
name: cloud-consul
serviceName: cloud-consul
template:
metadata:
creationTimestamp: null
labels:
name: cloud-consul
spec:
containers:
- args:
- agent
- '-server'
- '-bootstrap-expect=3'
- '-ui'
- '-data-dir=/consul/data'
- '-bind=0.0.0.0'
- '-client=0.0.0.0'
- '-advertise=$(POD_IP)'
- >-
-retry-join=cloud-consul-0.cloud-consul.$(NAMESPACE).svc.cluster.local
- >-
-retry-join=cloud-consul-1.cloud-consul.$(NAMESPACE).svc.cluster.local
- >-
-retry-join=cloud-consul-2.cloud-consul.$(NAMESPACE).svc.cluster.local
- '-domain=cluster.local'
- '-disable-host-node-id'
env:
- name: POD_IP
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: status.podIP
- name: NAMESPACE
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: metadata.namespace
image: 'consul:latest'
imagePullPolicy: IfNotPresent
name: consul
ports:
- containerPort: 8500
name: http
protocol: TCP
- containerPort: 8400
name: rpc
protocol: TCP
- containerPort: 8443
name: https-port
protocol: TCP
- containerPort: 8301
name: serf-lan
protocol: TCP
- containerPort: 8302
name: serf-wan
protocol: TCP
- containerPort: 8600
name: consul-dns
protocol: TCP
- containerPort: 8300
name: server
protocol: TCP
resources: {}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
dnsPolicy: ClusterFirst
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 10
updateStrategy:
rollingUpdate:
partition: 0
type: RollingUpdate
---
apiVersion: v1
kind: Service
metadata:
annotations: {}
labels:
name: cloud-consul
name: cloud-consul
namespace: default
spec:
ipFamilyPolicy: SingleStack
ports:
- name: http
port: 8500
protocol: TCP
targetPort: 8500
- name: https
port: 8443
protocol: TCP
targetPort: 8443
- name: rpc
port: 8400
protocol: TCP
targetPort: 8400
- name: serf-lan-tcp
port: 8301
protocol: TCP
targetPort: 8301
- name: serf-lan-udp
port: 8301
protocol: UDP
targetPort: 8301
- name: serf-wan-tcp
port: 8302
protocol: TCP
targetPort: 8302
- name: serf-wan-udp
port: 8302
protocol: UDP
targetPort: 8302
- name: server
port: 8300
protocol: TCP
targetPort: 8300
- name: consul-dns
port: 8600
protocol: TCP
targetPort: 8600
selector:
name: cloud-consul
sessionAffinity: None
type: ClusterIP
重点来了 只开放其中一个端口
---
apiVersion: v1
kind: Service
metadata:
name: cloud-consul-http
namespace: default
spec:
externalTrafficPolicy: Cluster
ipFamilies:
- IPv4
ipFamilyPolicy: SingleStack
ports:
- name: cloud-consul-tcp
nodePort: 30098
port: 8500
protocol: TCP
targetPort: 8500
selector:
name: cloud-consul
sessionAffinity: None
type: NodePort
总结
- 使用k8s安装集群端口使用 ClusterIP
- 而后通过 创建一个http的服务端口指向 ClusterIP