Step 1 - Kubernetes Cluster
We already installed minikube for you. To view the nodes in the cluster, run the kubectl get nodes command kubectl get nodes
This command shows all nodes that can be used to host our applications. Now we have only one node, and we can see that it’s status is ready (it is ready to accept applications for deployment).
Step 2 - Redis Master Controller
The first stage of launching the application is to start the Redis Master. A Kubernetes service deployment has, at least, two parts. A replication controller
and a service
.
The replication controller defines how many instances should be running, the Docker Image to use, and a name to identify the service. Additional options can be utilized for configuration and discovery. Use the editor above to view the YAML definition.
If Redis were to go down, the replication controller would restart it on an active node.
Create Replication Controller In this example, the YAML defines a redis server called redis-master using the official redis running port 6379.
The kubectl create command takes a YAML definition and instructs the master to start the controller.
kubectl create -f redis-master-controller.yaml
What's running? The above command created a Replication Controller. The Replication
kubectl get rc
All containers described as Pods. A pod is a collection of containers that makes up a particular application, for example Redis. You can view this using kubectl
kubectl get pods
redis-master-contoller.yaml
apiVersion: v1
kind: ReplicationController
metadata:
name: redis-master1
labels:
name: redis-master1
spec:
replicas: 2
selector:
name: redis-master1
template:
metadata:
labels:
name: redis-master1
spec:
containers:
- name: master
image: redis:3.0.7-alpine
ports:
- containerPort: 6379
Step 3 - Redis Master Service
The second part is a service. A Kubernetes service is a named load balancer that proxies traffic to one or more containers. The proxy works even if the containers are on different nodes.
Services proxy communicate within the cluster and rarely expose ports to an outside interface.
When you launch a service it looks like you cannot connect using curl or netcat unless you start it as part of Kubernetes. The recommended approach is to have a LoadBalancer service to handle external communications.
Create Service The YAML defines the name of the replication controller, redis-master, and the ports which should be proxied.
kubectl create -f redis-master-service.yaml
apiVersion: v1
kind: Service
metadata:
name: redis-master1
labels:
name: redis-master1
spec:
ports:
# the port that this service should serve on
- port: 6379
targetPort: 6379
selector:
name: redis-master1
kubectl get services
kubectl describe services redis-master