Kubernetes: redis-master using Minikube

This will create a redis-master using Minikube (no slaves or sentinels).

Create redis-deployment.yaml

vi redis-deployment.yaml
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
 name: redis
spec:
 replicas: 1
 template:
 metadata:
 labels:
 app: redis
 role: master
 tier: backend
 spec:
 containers:
 - name: redis
 image: redis
 resources:
 requests:
 cpu: 100m
 memory: 100Mi
 ports:
 - containerPort: 6379

Create redis-service.yaml

vi redis-service.yaml
---
apiVersion: v1
kind: Service
metadata:
 name: redis
 labels:
 app: redis
 role: master
 tier: backend
spec:
 type: NodePort
 ports:
 - port: 6379
 targetPort: 6379
 selector:
 app: redis
 role: master
 tier: backend

Create deployment and service

kubectl create -f .

Example

kubectl create -f .
deployment.extensions "redis" created
service "redis" created

Describe redis service

kubectl describe service redis

Example

Note the NodePort.

kubectl describe service redis
Name:                     redis
Namespace:                default
Labels:                   app=redis
                          role=master
                          tier=backend
Annotations:              <none>
Selector:                 app=redis,role=master,tier=backend
Type:                     NodePort
IP:                       10.0.0.24
Port:                     <unset>  6379/TCP
TargetPort:               6379/TCP
NodePort:                 <unset>  30285/TCP
Endpoints:                172.17.0.7:6379
Session Affinity:         None
External Traffic Policy:  Cluster

Connect to redis-master

redis-cli -h $(minikube ip) -p 30285

Clean up

kubectl delete -f .