尝试在Kubernetes上启动Redis

Windows 10
Docker 桌面版2.1.0.3(38240)
引擎版本:19.03.2
Compose版本:1.24.1
Kubernetes版本:v1.14.6

apiVersion: v1
kind: Service
metadata:
  name: redis
spec:
  ports:
    - port: 6379
      targetPort: 6379
  selector:
    app: redis
  clusterIP: None
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: redis.config
data:
  redis.conf: |
    requirepass password
    bind 0.0.0.0
---
apiVersion: apps/v1
kind: Deployment
metadata:
  # Deploymentの名前。Namespace内ではユニークである必要があります
  name: redis
spec:
  selector:
    matchLabels:
      app: redis
  # レプリカ数の指定
  replicas: 1
  # Podのテンプレート(PodTemplate)
  template:
    metadata:
      labels:
        # ラベル指定は必須
        app: redis
    spec:
      containers:
        - name: redis
          image: redis:5.0.5
          command: 
            - "redis-server"
            - "/redis-master/redis.conf"
          ports:
            - name: redis
              containerPort: 6379
          volumeMounts:
            - name: data
              mountPath: /redis-master-data
            - name: config
              mountPath: /redis-master
      volumes:
        - name: data
          emptyDir: {}
        - name: config
          configMap:
            name: redis.config
$ kubectl apply -f .\redis.yaml
$ kubectl get pod
NAME                     READY   STATUS    RESTARTS   AGE
redis-57f99c6c4c-lrqjs   1/1     Running   0          4m26s

$ kubectl exec -it redis-57f99c6c4c-lrqjs bash
root@redis-57f99c6c4c-lrqjs:/data# redis-cli
127.0.0.1:6379> auth password
OK
127.0.0.1:6379> set mykey "abc"
OK
127.0.0.1:6379> get mykey
"abc"
127.0.0.1:6379> exit
root@redis-57f99c6c4c-lrqjs:/data# exit
exit
广告
将在 10 秒后关闭
bannerAds