k8s部署redis

k8s部署redis

Scroll Down

redis.yaml

[root@k8s01 dh-env]# cat redis.yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  labels:
    app: dh-redis
  name: dh-redis
  namespace: dh-test
spec:
  replicas: 1
  selector:
    matchLabels:
      app: dh-redis
  template:
    metadata:
      labels:
        app: dh-redis
    spec:
      containers:
      - image: redis:5.0.2
        imagePullPolicy: IfNotPresent
        name: dh-redis
        ports:
        - containerPort: 6379
          protocol: TCP
      - image: oliver006/redis_exporter:latest
        imagePullPolicy: IfNotPresent
        name: redis-exporter
        resources:
          requests:
            cpu: 100m
            memory: 100Mi
        ports:
        - containerPort: 9121 
        volumeMounts:
        - mountPath: /etc/localtime
          name: host-time
        - mountPath: /etc/timezone
          name: time-zone
      volumes:
      - hostPath:
          path: /etc/localtime
          type: ""
        name: host-time
      - hostPath:
          path: /etc/timezone
          type: ""
        name: time-zone
---
apiVersion: v1
kind: Service
metadata:
  labels:
    app: dh-redis
  name: dh-redis
  namespace: dh-test
spec:
  ports:
  - name: redis-data
    port: 6379
    protocol: TCP
    targetPort: 6379
    nodePort: 31297
  - name: metrics
    port: 9121
    targetPort: 9121
  selector:
    app: dh-redis
  type: NodePort

[root@k8s01 ~]# kubectl get -n dh-test po
NAME                                   READY   STATUS             RESTARTS   AGE
dh-redis-594d87fc6-tzft9               2/2     Running            0          105m
[root@k8s01 ~]# kubectl get -n dh-test svc
NAME                      TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)                         AGE
dh-redis                  NodePort    10.101.89.95     <none>        6379:31297/TCP,9121:31460/TCP   105m