1、zookeeper_rc文件内容如下:

cat zookeeper.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: zookeeper
spec:
  replicas: 1
  selector:
    matchLabels:
      app: zookeeper
  minReadySeconds: 1
  progressDeadlineSeconds: 60
  revisionHistoryLimit: 5
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 1
  template:
    metadata:
      name: zookeeper
      labels:
        app: zookeeper
    spec:
      containers:
      - name: zookeeper
        image: zookeeper
        ports:
        - containerPort: 2181
        ports:
        - containerPort: 2888
        resources:
          limits:
            cpu: 10m                    #限制cpu最大的数量
            memory: 500Mi               #限制最大内存的大小
          requests:
            cpu: 10m                    #限制cpu最小的数量
            memory: 400Mi               #限制最小内存的大小
        volumeMounts:                   #挂载时间配置文件,使pod的时间和本地一致
        - name: tz-config
          mountPath: /etc/localtime
      volumes:
      - name: tz-config
        hostPath:
          path: /usr/share/zoneinfo/Asia/Shanghai

2、zookeeper_svc文件内容如下

cat zookeeper-svc.yaml
apiVersion: v1
kind: Service
metadata:
  name: zookeeper
spec:
  type: NodePort
  ports:
   - port: 2181
     nodePort: 30005
  selector:
    app: zookeeper

3、创建zookeeper

kubectl create -f zookeeper.yaml
kubectl create -f zookeeper-svc.yaml

4、检查是否启动pod

[root@k8s_master ~]# kubectl get pod --show-all
NAME                         READY   STATUS    RESTARTS   AGE
zookeeper-648df96574-hk8xq   1/1     Running   0          164m

[root@k8s_master ~]# kubectl get svc --all-namespaces
NAMESPACE     NAME                   TYPE        CLUSTER-IP       EXTERNAL-IP     PORT(S)             AGE
default       zookeeper              NodePort    10.254.186.178   <none>          2181:30005/TCP      158m
Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐