Kubernetes: From Experimenting with Minikube to AKS (Part2)

Raphael Gab-Momoh
Azure Nigeria Community Group
5 min readSep 9, 2022

The objective of this article is to help community members eliminate the fear of getting started with Kubernetes. In part 1, We looked at how to install a one-node cluster in our local environment using minikube and we tested it with a sample deployment. In part 2. We will do more of such deployments so that you can thoroughly get a full grip of the concepts before we start deploying to AKS in Part3. If you missed Part 1, you can check it out here Part1

Deploy A Simple Application

To deploy an application in a container, we will need to create a new deployment that is a Kubernetes object. The first thing to do would be to wake minikube up with the command

minikube start --driver=docker
minikube start

Now, let’s create the deployment. The name of the deployment will be Redis and the image we shall be using is Redis as well.

kubectl create deployment redis  --image=redis
deployment created

As we can see from the image above, deployment was successfully created, We can verify this deployment that we just made by running the command:

kubectl get deployments 
get deployment

Let’s view the deployment’s details with this command:

kubectl describe deployment redis
described

After running the command below take a look at the essential actions the cluster made to pull and install the new application. Several lines of output should appear. Note that each message’s age is displayed in the first column; however, the LAST SEEN time does not print out chronologically due to JSON’s lack of order.

kubectl get events
events before eventual creation

Viewing existing items in a usable YAML output is possible. See how redis is currently deployed.

kubectl get deployments redis -o yaml

Output

rdgmh@raphael:~$ kubectl get deployments redis -o yaml
apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
deployment.kubernetes.io/revision: "1"
creationTimestamp: "2022-09-07T23:12:31Z"
generation: 1
labels:
app: redis
name: redis
namespace: default
resourceVersion: "1418"
uid: 547c6dba-4eaa-4126-ac48-df67363b9e62
spec:
progressDeadlineSeconds: 600
replicas: 1
revisionHistoryLimit: 10
selector:
matchLabels:
app: redis
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
template:
metadata:
creationTimestamp: null
labels:
app: redis
spec:
containers:
- image: redis
imagePullPolicy: Always
name: redis
resources: {}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
dnsPolicy: ClusterFirst
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 30
status:
availableReplicas: 1
conditions:
- lastTransitionTime: "2022-09-07T23:15:09Z"
lastUpdateTime: "2022-09-07T23:15:09Z"
message: Deployment has minimum availability.
reason: MinimumReplicasAvailable
status: "True"
type: Available
- lastTransitionTime: "2022-09-07T23:12:31Z"
lastUpdateTime: "2022-09-07T23:15:09Z"
message: ReplicaSet "redis-64bd97b5fc" has successfully progressed.
reason: NewReplicaSetAvailable
status: "True"
type: Progressing
observedGeneration: 1
readyReplicas: 1
replicas: 1
updatedReplicas: 1
rdgmh@raphael:~$

We can create a service if we want to view more about our newly created redis container but we will have to change the configuration and add a port. So let’s create a deployment file with the command:

vim deploymentfile.yml

Let’s populate the file with data by copying data from a similar file in Kubernetes documentation. Here is a link to it. Please note that we replaced wherever there was nginx with redis and added the section for port, and protocol. A sample is shown below:

apiVersion: apps/v1
kind: Deployment
metadata:
name: redis
labels:
app: redis
spec:
replicas: 3
selector:
matchLabels:
app: redis
template:
metadata:
labels:
app: redis
spec:
containers:
- name: redis
image: redis
ports:
- containerPort: 80
protocol: TCP

Remember the reason why we did this was that we could not run the service successfully because the previous deployment had no port and protocol. So now that we have created a YAML file and indicated it, we will use replace to terminate and create a new deployment.

kubectl replace -f deploymentfile.yml
replaced

View the Pod and Deployment. Note the AGE shows the Pod was re-created.

kubectl get deploy,pod
kubect get deployment, pods

Now let’s try to expose the resource again. This time it should work.

kubectl expose deployment redis
exposed

Verify the service configuration

kubectl get svc redis
service

The Endpoint is provided by kubelet and kube-proxy. Take note of the current endpoint IP

kubectl get ep redis
endpoint

We can choose to take a look at all the pods created and describe the first one

kubectl get pods
pods
describe the first pod

Now scale up the deployment from 3 to 6 redis databases

kubectl get deployment redis
deployment

We can scale from the current number we have to 6 using the command:

kubectl scale deployment redis --replicas=6
scaled

Now that we have successfully scaled our deployment, let’s check the number of pods that we have again

kubectl get deployment redis 
six

View the current endpoints. There now should be six

kubectl get ep redis 
endpoints

Let’s get the IP addresses of all running pods another way by using -o wide

kubectl get pod -o wide
-o wide

Let’s clean up by deleting our deployment

kubectl delete deployment redis
delete deployment

Let’s check again if our deployment is still there

error

Summary

Remember that Minikube is specifically for learning and experimentation and not for production purposes. As we can see, it does what it’s meant for very well as it can be used to perform any Kubernetes operation. In this article, we went through the common use cases that every first learner will come across.

--

--

Raphael Gab-Momoh
Azure Nigeria Community Group

Experienced Cloud Engineer with a demonstrated history of working in the information technology and services industry.