What is Kubernetes?
Kubernetes also known as K8s.
K8s [ K - First letter, 8 - count of characters between K & s (ubernete), s -> Last Letter ]
It's used to manage containers. It's an open-source system for automating the deployment, scaling, and management of containerized applications.
Originally designed by Google, the project is now maintained by the "Cloud Native Computing Foundation (CNCF)".
Kubernetes source code is in the "Go language".
The design and development of Kubernetes were influenced by Google's Borg cluster manager. Many of its top contributors had previously worked on Borg; they codenamed Kubernetes "Project 7" after the Star Trek ex-Borg character Seven of Nine and gave its logo a "seven-spoked wheel".
Let's start with Minikube:
Why minikube ?
minikube is local Kubernetes, focusing on making it easy to learn and develop for Kubernetes. Here, AWS Instance is used for the whole Lab setup.
1) Create an AWS instance with the following configuration:
. Name of the Instance: "minikube" ( can be anything )
- Application & OS Image: Select "ubuntu"
- Instance Type: Select "t2.medium" ( pre-requisite is 2 vCPU for minikube)
Create a new key pair - minikube.ppk (for Putty connection )
minimum 20GB of storage disk space
Other Settings: Keep it as default.
Click on "Launch Instance"
The AWS t2.medium Instance is ready for use.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2) Connect to the Instance and install docker, kubectl and minikube.
- Run with sudo privileges.
sudo su
2. Update all the packages.
apt-get update
3. Install Docker on the ubuntu instance.
apt-get install
docker.io
4. Docker Installation will take a few minutes to complete, verify the docker installation.
docker --version
5. Now, let's install the Kubernetes command-line tool - kubectl.
kubectl - allows you to run commands against Kubernetes clusters. kubectl can be used to deploy applications, inspect and manage cluster resources, and view logs.
(Follow steps from kubernetes.io/docs/tasks/tools/install-kube..)
- Download the kubectl
curl -LO "
[https://dl.k8s.io/release/$(curl
](dl.k8s.io/release/$(curl) -L -s
https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl
/bin/linux/amd64/kubectl)"
- Make the file executable via chmod +x.
chmod +x ./kubectl
- Move the executable kubectl file under /usr/local/bin
mv ./kubectl /usr/local/bin/kubectl
6. Kubectl is installed, now let's install minikube, the Debian package.
- Download the package
curl -LO
https://storage.googleapis.com/minikube/releases/latest/minikube_latest_amd64.deb
- Unpack the package
sudo dpkg -i minikube_latest_amd64.deb
- minikube is installed, verify the version.
minikube version
- start the minikube server
minikube start --force
- Now, check the kubectl version command, it provides the server version details too.
kubectl version
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3) Creating Pod using a Kubernetes manifest file.
We have an infrastructure ready with the required applications. Let's create a manifests YAML file, to create Pod on minikube server. A manifest specifies the desired state of an object that Kubernetes will maintain when you apply the manifest.
Pods are the smallest deployable units of computing that you can create and manage in Kubernetes. It is a group of one or more containers, with shared storage and network resources, and a specification for how to run the containers.
Here, we are creating a single container "c0" within a Pod.
Details on myfirstpod.yml
manifest myfirstpod.yml file code are below for reference.
kind: Pod
apiVersion: v1
metadata:
name: myfirstpod
spec:
containers:
- name: c0
image: ubuntu
command: ["/bin/bash", "-c", "while true; do echo Hello-World!; sleep 10 ; done"]
restartPolicy: Never
- Create the myfirstpod.yml manifest file.
ls -lrt
- Apply the manifest file to create the pod
kubectl apply -f myfirstpod.yml
- Check the pods created
kubectl get pods
- For detailed output, use -
kubectl get pods -o wide
. [Note: IP is assigned to POD, not to containers. ]
root@ip-172-31-8-148:/home/ubuntu# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
myfirstpod 1/1 Running 0 4m50s 172.17.0.3 minikube <none> <none>
- To view the detail events while creating POD:-
kubectl describe pod/myfirstpod
Events
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 17m default-scheduler Successfully assigned default/myfirstpod to minikube
Normal Pulling 17m kubelet Pulling image "ubuntu"
Normal Pulled 17m kubelet Successfully pulled image "ubuntu" in 5.358130716s
Normal Created 17m kubelet Created container c0
Normal Started 17m kubelet Started container c0:
- Check the logs of the container "c0" :
kubectl logs -f myfirstpod -c c0
root@ip-172-31-8-148:/home/ubuntu# kubectl logs -f myfirstpod -c c0
Hello-World!
Hello-World!
Hello-World!
Hello-World!
Hello-World!
Hello-World!
Hello-World!
Hello-World!
Hello-World!
Hello-World!
Hello-World!
Hello-World!
Hope, this article gives you a headstart to learn Kubernetes !!
References: