在k8s创建的容器内部,需要访问外部的虚拟IP可以在yaml中增加externalIPs对应的value为虚拟IP
apiVersion: v1
kind: Service
metadata:
labels:
app: zookeeper-service
name: zookeeper-service
spec:
# type: NodePort
ports:
- name: zookeeper-port
port: 2181
targetPort: 2181
# nodePort: 30181
# protocol: TCP
externalIPs:
- 10.160.100.145
selector:
app: zookeeper
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
labels:
app: zookeeper
name: zookeeper
spec:
replicas: 1
template:
metadata:
labels:
app: zookeeper
spec:
containers:
- image: zookeeper:latest
imagePullPolicy: Always
name: zookeeper
ports:
- containerPort: 2181