一键建立zookeeper集群
使用yaml文件的好处,通过service name来进行pod间的服务发现,
集群配置dns.
[root@k8s-master ~]# cat zookeeper-cluster.yaml apiVersion: extensions/v1beta1 kind: Deployment metadata: name: zookeeper-1 spec: replicas: 1 template: metadata: labels: name: zookeeper-1 spec: containers: - name: zookeeper-1 image: docker.io/zookeeper:3.4.11 imagePullPolicy: IfNotPresent env: - name: ZOO_MY_ID value: "1" - name: ZOO_SERVERS value: "server.1=0.0.0.0:2888:3888 server.2=zookeeper-2:2888:3888 server.3=zookeeper-3:2888:3888" ports: - containerPort: 2181 --- apiVersion: extensions/v1beta1 kind: Deployment metadata: name: zookeeper-2 spec: replicas: 1 template: metadata: labels: name: zookeeper-2 spec: containers: - name: zookeeper-2 image: docker.io/zookeeper:3.4.11 imagePullPolicy: IfNotPresent env: - name: ZOO_MY_ID value: "2" - name: ZOO_SERVERS value: "server.1=zookeeper-1:2888:3888 server.2=0.0.0.0:2888:3888 server.3=zookeeper-3:2888:3888" ports: - containerPort: 2181 --- apiVersion: extensions/v1beta1 kind: Deployment metadata: name: zookeeper-3 spec: replicas: 1 template: metadata: labels: name: zookeeper-3 spec: containers: - name: zookeeper-3 image: docker.io/zookeeper:3.4.11 imagePullPolicy: IfNotPresent env: env: - name: ZOO_MY_ID value: "3" - name: ZOO_SERVERS value: "server.1=zookeeper-1:2888:3888 server.2=zookeeper-2:2888:3888 server.3=0.0.0.0:2888:3888" ports: - containerPort: 2181 --- apiVersion: v1 kind: Service metadata: name: zookeeper-1 labels: name: zookeeper-1 spec: ports: - name: client port: 2181 protocol: TCP - name: followers port: 2888 protocol: TCP - name: election port: 3888 protocol: TCP selector: name: zookeeper-1 --- apiVersion: v1 kind: Service metadata: name: zookeeper-2 labels: name: zookeeper-2 spec: ports: - name: client port: 2181 protocol: TCP - name: followers port: 2888 protocol: TCP - name: election port: 3888 protocol: TCP selector: name: zookeeper-2 --- apiVersion: v1 kind: Service metadata: name: zookeeper-3 labels: name: zookeeper-3 spec: ports: - name: client port: 2181 protocol: TCP - name: followers port: 2888 protocol: TCP - name: election port: 3888 protocol: TCP selector: name: zookeeper-3