https://www.wulaoer.org/?p=2290
[wolf@wulaoer.org🔥🔥🔥🔥 docker]# cat Dockerfile FROM wolf27w/centos7-jdk:1.0 WORKDIR /usr/local #RUN wget https://downloads.apache.org/zookeeper/zookeeper-3.6.3/apache-zookeeper-3.6.3-bin.tar.gz #RUN tar -zxf apache-zookeeper-3.6.3-bin.tar.gz && mv apache-zookeeper-3.6.3-bin zookeeper && rm -rf apache-zookeeper-3.6.3-bin.tar.gz COPY apache-zookeeper-3.6.3-bin zookeeper ENV ZOOKEEPER_HOME /usr/local/zookeeper ENV PATH $PATH:$ZOOKEEPER_HOME/bin ADD zoo.cfg $ZOOKEEPER_HOME/conf/zoo.cfg EXPOSE 2181 CMD $ZOOKEEPER_HOME/bin/zkServer.sh start-foreground [wolf@wulaoer.org🔥🔥🔥🔥 docker]# docker build -t zookeeper:3.6.3 .
如果你的基础镜像已经安装了wget,可以直接替换成自己的基础镜像即可,但是基础镜像必须安装了jdk,我这里已经安装了,为了方便没有基础镜像的就注释掉了,然后下载到本地即可。
制作成镜像,需要传到仓库中,但是建议在上传到仓库之前可以进入容器运行一下,如果没有问题在上传。
[wolf@wulaoer.org🔥🔥🔥🔥 docker]# docker tag zookeeper:3.6.3 wolf27w/zookeeper:3.6.3 [wolf@wulaoer.org🔥🔥🔥🔥 docker]# docker push wolf27w/zookeeper:3.6.3
镜像已经上传完成,下面开始写kubernetes的yaml文件,这里有两个注意事项,第一个是pv和pvc,第二个就是访问方式,我这里使用的是nodeport,如果在一个集群中可以直接请求。
[wolf@wulaoer.org🔥🔥🔥🔥 docker]# cat zookeeper.yaml apiVersion: v1 kind: Service metadata: name: zookeeper namespace: zookeeper-system labels: app: zookeeper spec: type: NodePort ports: - port: 2181 selector: app: zookeeper tier: zookeeper --- apiVersion: v1 kind: PersistentVolumeClaim metadata: name: zookeeper-pv-claim namespace: zookeeper-system labels: app: zookeeper spec: storageClassName: rook-cephfs accessModes: - ReadWriteOnce resources: requests: storage: 10Gi --- apiVersion: apps/v1 kind: Deployment metadata: name: zookeeper namespace: zookeeper-system labels: app: zookeeper tier: zookeeper spec: selector: matchLabels: app: zookeeper tier: zookeeper strategy: type: Recreate template: metadata: labels: app: zookeeper tier: zookeeper spec: containers: - image: wolf27w/zookeeper:3.6.3 name: zookeeper ports: - containerPort: 2181 name: zookeeper volumeMounts: - name: zookeeper-persistent-storage mountPath: /usr/local/zookeeper/data volumes: - name: zookeeper-persistent-storage persistentVolumeClaim: claimName: zookeeper-pv-claim
上面从ceph中创建一个名为zookeeper-pv-claim的pv,并关联到zookeeper的数据目录下,这样就能保证zookeeper的数据能够持续华。
[wolf@wulaoer.org🔥🔥🔥🔥 docker]# kubectl apply -f zookeeper.yaml service/zookeeper created persistentvolumeclaim/zookeeper-pv-claim unchanged [wolf@wulaoer.org🔥🔥🔥🔥 docker]# kubectl get pod -n zookeeper-system NAME READY STATUS RESTARTS AGE zookeeper-58c6754486-jbflw 1/1 Running 0 35m [wolf@wulaoer.org🔥🔥🔥🔥 docker]# kubectl get svc -n zookeeper-system NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE zookeeper NodePort 172.16.183.224 <none> 2181:32586/TCP 36m
zookeeper单机集群就创建好了,对外端口也创建出来了,直接利用node的ip加32586端口直接访问即可,zookeeper在kubernetes上单机部署就完成了。
您可以选择一种方式赞助本站
支付宝扫一扫赞助
微信钱包扫描赞助
赏