INSTALL MINIKUBE ON UBUNTU AND DEPLOY APPLICATION
First, update your system with the latest version, You can do this with the help of the following command:
apt-get update -y && apt-get upgrade -y
apt-get update command gets you an updated list of packages from the Internet. apt-get upgrade to install available upgrades of all packages currently installed on the system.
Install some required packages with the following command:
sudo apt-get install socatsudo apt-get install curlsudo apt-get install apt-transport-httpssudo apt install conntrack
Minikube supports both KVM and VirtualBox Hypervisor. So, you will need to install KVM or VirtualBox to your system.
You can install VirtualBox with the following command:
apt-get install virtualbox virtualbox-ext-pack
Once the installation is done, we can proceed to the next step.
Download the latest version of Minikube in your system .You can download it from the official website, with the following command.
wget https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
Once the download is completed, copy the downloaded file under /usr/local/bin with the following command:
cp minikube-linux-amd64 /usr/local/bin/minikube
Next, give execution permission to the minikube with the following command:
sudo chmod 777 /usr/local/bin/minikube
Now, check the version of Minikube
The Kubernetes command-line tool, kubectl, allows you to run commands against Kubernetes clusters. You can use kubectl to deploy applications to inspect and manage cluster resources and view logs. By default, Kubectl is not available in the Ubuntu 20.04 default repository. So, you will need to add the Kubernetes repository to your system.
sudo curl -LO https://storage.googleapis.com/kubernetes-release/release/` curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl
Next, give execution permission to the kubectl with the following command:
Next, Move the files under /usr/local/bin with the following command:
sudo mv ./kubectl /usr/local/bin/kubectl
Now, verify whether kubectl is installed or not.
Output after executing the above command looks like:
devops@Devops:~$sudo kubectl version -o json
{
"clientVersion": {
"major": "1",
"minor": "20",
"gitVersion": "v1.20.5",
"gitCommit": "6b1d87acf3c8253c123756b9e61dac642678305f",
"gitTreeState": "clean",
"buildDate": "2021-03-18T01:10:43Z",
"goVersion": "go1.15.8",
"compiler": "gc",
"platform": "linux/amd64"
}
}
Now, start the cluster, using the following command
minikube start --vm-driver=none
Output after executing the above command looks like:
devops@Devops:~$ ❗ The 'none' driver is designed for experts who need to integrate with an existing VM❗ kubectl and minikube configuration will be stored in /root▪ sudo mv /root/.kube /root/.minikube $HOME💡 This can also be done automatically by setting the env var CHANGE_MINIKUBE_NONE_USER=truesudo minikube start --vm-driver=none
💡 Most users should use the newer 'docker' driver instead, which does not require root!
❗ To use kubectl or minikube commands as your own user, you may need to relocate them. For example, to overwrite your own settings, run:
▪ sudo chown -R $USER $HOME/.kube $HOME/.minikube
🔎 Verifying Kubernetes components...
▪ Using image gcr.io/k8s-minikube/storage-provisioner:v4
🌟 Enabled addons: storage-provisioner, default-storageclass
🏄 Done! kubectl is now configured to use "minikube" cluster and "default" namespace by default
📘 For more information, see: https://minikube.sigs.k8s.io/docs/reference/drivers/none/
😄 minikube v1.18.1 on Ubuntu 20.04
✨ Using the none driver based on user configuration
👍 Starting control plane node minikube in cluster minikube
🤹 Running on localhost (CPUs=4, Memory=3921MB, Disk=937367MB) ...
ℹ️ OS release is Ubuntu 20.04.2 LTS
🐳 Preparing Kubernetes v1.20.2 on Docker 19.03.8 ...
▪ kubelet.resolv-conf=/run/systemd/resolve/resolv.conf
🤹 Configuring local host environment ...
The cluster can be interacted with using the kubectl CLI. This is the main approach used for managing Kubernetes and the applications running on the
top of the cluster.
Kubernetes Commands:
Details of the cluster and its health status can be known using:
devops@Devops:~$sudo kubectl cluster-info
Kubernetes control plane is running at https://172.16.1.254:8443
KubeDNS is running at https://172.16.1.254:8443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
To view nodes in the cluster:
devops@Devops:~$sudo kubectl get pods
NAME READY STATUS RESTARTS AGE
rps-node-9448598d4-d48q2 1/1 Running 0 38s
Now check the config view of kubectl:
devops@Devops:~$sudo kubectl config view
apiVersion: v1
clusters:
- cluster:
certificate-authority: /root/.minikube/ca.crt
extensions:
- extension:
last-update: Wed, 07 Apr 2021 22:36:09 IST
provider: minikube.sigs.k8s.io
version: v1.18.1
name: cluster_info
server: https://172.16.1.254:8443
name: minikube
contexts:
- context:
cluster: minikube
extensions:
- extension:
last-update: Wed, 07 Apr 2021 22:36:09 IST
provider: minikube.sigs.k8s.io
version: v1.18.1
name: context_info
namespace: default
user: minikube
name: minikube
current-context: minikube
kind: Config
preferences: {}
users:
- name: minikube
user:
client-certificate: /root/.minikube/profiles/minikube/client.crt
client-key: /root/.minikube/profiles/minikube/client.key
Let’s run our first app on Kubernetes with the kubectl run command. The run command creates a new deployment. We need to provide the deployment name and the app image location. If we want to run the app on a specific port so we could add the -port parameter as well.
First let us check the images in Docker Container
devops@Devops:~$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest d1165f221234 4 weeks ago 13.3kB
k8s.gcr.io/kube-proxy v1.20.2 43154ddb57a8 2 months ago 118MB
k8s.gcr.io/kube-controller-manager v1.20.2 a27166429d98 2 months ago 116MB
k8s.gcr.io/kube-apiserver v1.20.2 a8c2fdb8bf76 2 months ago 122MB
k8s.gcr.io/kube-scheduler v1.20.2 ed2c44fbdd78 2 months ago 46.4MB
gcr.io/k8s-minikube/storage-provisioner v4 85069258b98a 4 months ago 29.7MB
k8s.gcr.io/etcd 3.4.13-0 0369cf4303ff 7 months ago 253MB
k8s.gcr.io/coredns 1.7.0 bfe3a36ebd25 9 months ago 45.2MB
k8s.gcr.io/pause 3.2 80d28bedfe5d 13 months ago 683kB
Now, we are pulling a rock, paper, scissors Application from Docker hub Repository:
devops@Devops:~$sudo docker pull cameronmcnz/rock-paper-spring
Using default tag: latest
latest: Pulling from cameronmcnz/rock-paper-spring
e7c96db7181b: Pull complete
f910a506b6cb: Pull complete
c2274a1a0e27: Pull complete
c074e774d6b4: Pull complete
Digest: sha256:254156362917ff4063e402669ade30504bccbaa6b50bf30f2f4dbdb1d8e69a91
Status: Downloaded newer image for cameronmcnz/rock-paper-spring:latest
docker.io/cameronmcnz/rock-paper-spring:latest
Every Kubernetes Node runs at least:
1.Kubelet — responsible for communicating between the Kubernetes
Master and the Nodes
2.Container runtime (Docker)
To list all your deployments:
kubectl get deployment
Some useful Kubectl commands
kubectl get — list resources
kubectl describe — show detailed information about a resource
kubectl logs — prints the logs from a container in pod
kubectl exec — execute a command on a container in a pod
devops@Devops:~$ sudo kubectl create deployment rps-node --image="cameronmcnz/rock-paper-spring"
deployment.apps/rps-node created
A Pod is Kubernetes abstraction that represents a group of one or more
Application containers (such as Docker) and some shared resources
for those containers. Those resources include:
-> Shared storage, as volumes.
-> Networking, as a unique cluster IP address.
-> Information about how to run each container, such as the container image version or specific ports to use.
To expose the app to the outside world, we use the expose deployment command.
devops@Devops:~$sudo kubectl expose deployment rps-node --type=LoadBalancer --port=8080
service/rps-node exposed
Pods that are running inside Kubernetes are running on a private, isolated network. By default, they are visible from other pods and services within the same Kubernetes cluster, but not outside that network. On some platforms (for example, Google Compute Engine) the kubectl command can integrate with your cloud provider to add a public IP address for the pods to do this run.
Now, we are forwarding the port number from 8080:7070 to access the page of Application
devops@Devops:~$sudo kubectl port-forward service/rps-node 7070:8080
Forwarding from 127.0.0.1:7070 -> 8080
Forwarding from [::1]:7070 -> 8080
Handling connection for 7070
Handling connection for 7070
Handling connection for 7070
Handling connection for 7070
From the output, we see CLUSTER-IP or localhost with portnumber will be enter the IP in the crome we see its respective landing page.
rock-paper-spring application
Originally published at https://pranavparamesh.medium.com on April 8, 2021.