0% found this document useful (0 votes)
3 views

install kubernetes in OCI

The document details the installation and setup of Kubernetes tools, specifically kubectl and minikube, on an Oracle Linux 8 system. It includes commands for downloading, verifying, and installing these tools, as well as troubleshooting issues related to driver detection and running Kubernetes pods. The document concludes with the successful creation and verification of a sample nginx pod running in the minikube environment.

Uploaded by

raja sinha
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

install kubernetes in OCI

The document details the installation and setup of Kubernetes tools, specifically kubectl and minikube, on an Oracle Linux 8 system. It includes commands for downloading, verifying, and installing these tools, as well as troubleshooting issues related to driver detection and running Kubernetes pods. The document concludes with the successful creation and verification of a sample nginx pod running in the minikube environment.

Uploaded by

raja sinha
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 20

[opc@kubernetes ~]$ sudo su

[root@kubernetes opc]# curl -LO "https://dl.k8s.io/release/$(curl -L -s


https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"

% Total % Received % Xferd Average Speed Time Time Time Current

Dload Upload Total Spent Left Speed

100 138 100 138 0 0 3000 0 --:--:-- --:--:-- --:--:-- 3000

100 49.0M 100 49.0M 0 0 175M 0 --:--:-- --:--:-- --:--:-- 175M

[root@kubernetes opc]# curl -LO "https://dl.k8s.io/release/$(curl -L -s


https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl.sha256"

% Total % Received % Xferd Average Speed Time Time Time Current

Dload Upload Total Spent Left Speed

100 138 100 138 0 0 3136 0 --:--:-- --:--:-- --:--:-- 3136

100 64 100 64 0 0 1066 0 --:--:-- --:--:-- --:--:-- 1066

[root@kubernetes opc]# echo "$(cat kubectl.sha256) kubectl" | sha256sum --check

kubectl: OK

[root@kubernetes opc]# sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl

[root@kubernetes opc]# kubectl version --client --output=yaml

bash: kubectl: command not found

[root@kubernetes opc]# /usr/local/bin/kubectl version --client --output=yaml

clientVersion:

buildDate: "2024-04-17T17:36:05Z"

compiler: gc

gitCommit: 7c48c2bd72b9bf5c44d21d7338cc7bea77d0ad2a

gitTreeState: clean

gitVersion: v1.30.0

goVersion: go1.22.2

major: "1"

minor: "30"

platform: linux/amd64

kustomizeVersion: v5.0.4-0.20230601165947-6ce0bf390ce3

[root@kubernetes opc]#
[root@kubernetes opc]# /usr/local/bin/kubectl version

Client Version: v1.30.0

Kustomize Version: v5.0.4-0.20230601165947-6ce0bf390ce3

The connection to the server localhost:8080 was refused - did you specify the right host or port?

[root@kubernetes opc]#

Install minikube:-

[root@kubernetes opc]# curl -LO


https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 91.2M 100 91.2M 0 0 114M 0 --:--:-- --:--:-- --:--:-- 114M
[root@kubernetes opc]# sudo install minikube-linux-amd64 /usr/local/bin/minikube &&
rm minikube-linux-amd64
rm: remove regular file 'minikube-linux-amd64'? yes
[root@kubernetes opc]#

[root@kubernetes opc]# /usr/local/bin/minikube start


* minikube v1.33.0 on Oracle 8.9 (amd64)
* Unable to pick a default driver. Here is what was considered, in preference order:
* Alternatively you could install one of these drivers:
- docker: Not installed: exec: "docker": executable file not found in $PATH
- kvm2: Not installed: exec: "virsh": executable file not found in $PATH
- podman: Not installed: exec: "podman": executable file not found in $PATH
- qemu2: Not installed: exec: "qemu-system-x86_64": executable file not found in $PATH
- virtualbox: Not installed: unable to find VBoxManage in $PATH

X Exiting due to DRV_NOT_DETECTED: No possible driver was detected. Try specifying --


driver, or see https://minikube.sigs.k8s.io/docs/start/

[root@kubernetes opc]#

Install Minikube on OCI Linux 8


https://docs.oracle.com/en/learn/ol-minikube/#for-more-information

[root@kubernetes-cluster opc]# dnf -y update

sudo dnf install -y podman podman-docker conntrack

[root@kubernetes-cluster opc]# cd ~; curl -LO


https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 91.2M 100 91.2M 0 0 192M 0 --:--:-- --:--:-- --:--:-- 192M
[root@kubernetes-cluster ~]#
[root@kubernetes-cluster ~]# sudo install minikube-linux-amd64 /usr/local/bin/minikube
[root@kubernetes-cluster ~]# minikube start --driver=podman
* minikube v1.33.0 on Oracle 8.9 (kvm/amd64)
* Using the podman driver based on user configuration
* The "podman" driver should not be used with root privileges. If you wish to continue as
root, use --force.
* If you are running minikube within a VM, consider using --driver=none:
* https://minikube.sigs.k8s.io/docs/reference/drivers/none/

X Exiting due to DRV_AS_ROOT: The "podman" driver should not be used with root
privileges.

[root@kubernetes-cluster ~]# exit


exit
[opc@kubernetes-cluster ~]$ minikube start --driver=podman
* minikube v1.33.0 on Oracle 8.9 (kvm/amd64)
* Using the podman driver based on user configuration
* Using Podman driver with root privileges
* Starting "minikube" primary control-plane node in "minikube" cluster
* Pulling base image v0.0.43 ...
* Downloading Kubernetes v1.30.0 preload ...
> preloaded-images-k8s-v18-v1...: 342.90 MiB / 342.90 MiB 100.00% 97.57 M
> gcr.io/k8s-minikube/kicbase...: 480.29 MiB / 480.29 MiB 100.00% 104.15
E0513 14:20:07.155749 93372 cache.go:189] Error downloading kic artifacts: not yet
implemented, see issue #8426
* Creating podman container (CPUs=2, Memory=3900MB) ...|
* Preparing Kubernetes v1.30.0 on Docker 26.0.1 ...
- Generating certificates and keys ...
- Booting up control plane ...
- Configuring RBAC rules ...
* Configuring bridge CNI (Container Networking Interface) ...
* Verifying Kubernetes components...
- Using image gcr.io/k8s-minikube/storage-provisioner:v5
* Enabled addons: storage-provisioner, default-storageclass
* Done! kubectl is now configured to use "minikube" cluster and "default" namespace by
default
[opc@kubernetes-cluster ~]$

Command- minikube status


kubectl get all

Verify
[opc@kubernetes-cluster ~]$ minikube kubectl -- get pods -A
> kubectl.sha256: 64 B / 64 B [-------------------------] 100.00% ? p/s 0s
> kubectl: 49.07 MiB / 49.07 MiB [------------] 100.00% 1.15 GiB p/s 200ms
NAMESPACE NAME READY STATUS RESTARTS AGE
kube-system coredns-7db6d8ff4d-mrc5p 1/1 Running 0 19s
kube-system etcd-minikube 1/1 Running 0 32s
kube-system kube-apiserver-minikube 1/1 Running 0 34s
kube-system kube-controller-manager-minikube 1/1 Running 0 32s
kube-system kube-proxy-vc97q 1/1 Running 0 19s
kube-system kube-scheduler-minikube 1/1 Running 0 32s
kube-system storage-provisioner 1/1 Running 0 31s
[opc@kubernetes-cluster ~]$

[opc@kubernetes-cluster ~]$ kubectl get nodes

NAME STATUS ROLES AGE VERSION

minikube Ready control-plane 2m50s v1.30.0

[opc@kubernetes-cluster ~]$

Stop minikube

[opc@kubernetes-cluster ~]$ minikube stop --driver=podman


Error: unknown flag: --driver

See 'minikube stop --help' for usage.

[opc@kubernetes-cluster ~]$ minikube stop --all

* Stopping node "minikube" ...

* Powering off "minikube" via SSH ...

* Stopping node "minikube" ...

* Powering off "minikube" via SSH ...

* Stopping node "minikube" ...

* 1 node stopped.

[opc@kubernetes-cluster ~]$ kubectl get nodes

E0513 14:28:11.613557 100931 memcache.go:265] couldn't get current server API group list: Get
"http://localhost:8080/api?timeout=32s": dial tcp [::1]:8080: connect: connection refused

E0513 14:28:11.614150 100931 memcache.go:265] couldn't get current server API group list: Get
"http://localhost:8080/api?timeout=32s": dial tcp [::1]:8080: connect: connection refused

E0513 14:28:11.615836 100931 memcache.go:265] couldn't get current server API group list: Get
"http://localhost:8080/api?timeout=32s": dial tcp [::1]:8080: connect: connection refused

E0513 14:28:11.616331 100931 memcache.go:265] couldn't get current server API group list: Get
"http://localhost:8080/api?timeout=32s": dial tcp [::1]:8080: connect: connection refused

E0513 14:28:11.617955 100931 memcache.go:265] couldn't get current server API group list: Get
"http://localhost:8080/api?timeout=32s": dial tcp [::1]:8080: connect: connection refused

The connection to the server localhost:8080 was refused - did you specify the right host or port?

[opc@kubernetes-cluster ~]$

Create the PODs

https://kubernetes.io/docs/concepts/workloads/pods/

cat pod.yml

[opc@kubernetes-cluster ~]$ cat pod.yml


apiVersion: v1
kind: Pod
metadata:
name: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
[opc@kubernetes-cluster ~]$

[opc@kubernetes-cluster ~]$ kubectl create -f pod.yml


pod/nginx created
[opc@kubernetes-cluster ~]$

[opc@kubernetes-cluster ~]$ kubectl get pods


NAME READY STATUS RESTARTS AGE
nginx 1/1 Running 0 37s
[opc@kubernetes-cluster ~]$
[opc@kubernetes-cluster ~]$ kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED
NODE READINESS GATES
nginx 1/1 Running 0 62s 10.244.0.4 minikube <none>
<none>
[opc@kubernetes-cluster ~]$
[opc@kubernetes-cluster ~]$ minikube ssh
docker@minikube:~$ curl 10.244.0.4
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to


<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>


</body>
</html>
docker@minikube:~$

come out of the pod

docker@minikube:~$ exit
logout
ssh: Process exited with status 130
[opc@kubernetes-cluster ~]$ kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED
NODE READINESS GATES
nginx 1/1 Running 0 4m49s 10.244.0.4 minikube <none>
<none>
[opc@kubernetes-cluster ~]$

Describe pod

[opc@kubernetes-cluster ~]$ kubectl describe pod nginx


Name: nginx
Namespace: default
Priority: 0
Service Account: default
Node: minikube/192.168.49.2
Start Time: Tue, 14 May 2024 09:18:55 +0000
Labels: <none>
Annotations: <none>
Status: Running
IP: 10.244.0.4
IPs:
IP: 10.244.0.4
Containers:
nginx:
Container ID:
docker://7d9351efe00961b275ec4a6be2b13ad32cbd394acb4dc789c3bdab3f7
e052fb2
Image: nginx:1.14.2
Image ID:
docker-pullable://nginx@sha256:f7988fb6c02e0ce69257d9bd9cf37ae20a60f1
df7563c3a2a6abe24160306b8d
Port: 80/TCP
Host Port: 0/TCP
State: Running
Started: Tue, 14 May 2024 09:18:59 +0000
Ready: True
Restart Count: 0
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-sxgq2
(ro)
Conditions:
Type Status
PodReadyToStartContainers True
Initialized True
Ready True
ContainersReady True
PodScheduled True
Volumes:
kube-api-access-sxgq2:
Type: Projected (a volume that contains injected data from
multiple sources)
TokenExpirationSeconds: 3607
ConfigMapName: kube-root-ca.crt
ConfigMapOptional: <nil>
DownwardAPI: true
QoS Class: BestEffort
Node-Selectors: <none>
Tolerations: node.kubernetes.io/not-ready:NoExecute op=Exists for
300s
node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 8m26s default-scheduler Successfully assigned
default/nginx to minikube
Normal Pulling 8m25s kubelet Pulling image "nginx:1.14.2"
Normal Pulled 8m22s kubelet Successfully pulled image
"nginx:1.14.2" in 3.525s (3.525s including waiting). Image size: 109109325
bytes.
Normal Created 8m22s kubelet Created container nginx
Normal Started 8m22s kubelet Started container nginx
[opc@kubernetes-cluster ~]$
============================

Kubernetes is meant for enterprise solution and docker is not.


Kubernetes has features known as auto healing, load balancing.
In Kubernetes, containers>>>Pod>>
Auto healing is enables by deployment
Deployment >>Replica set>>pod
That means if I use deployment and delete a pod, immediately a new pod will
be created.

Deployment

[opc@kubernetes-cluster ~]$ cat deployment.yaml


apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 2
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
[opc@kubernetes-cluster ~]$
Apply ~create
[opc@kubernetes-cluster ~]$ kubectl apply -f deployment.yaml
deployment.apps/nginx-deployment created
[opc@kubernetes-cluster ~]$
[opc@kubernetes-cluster ~]$ kubectl get deploy
NAME READY UP-TO-DATE AVAILABLE AGE
nginx-deployment 2/2 2 2 50s
[opc@kubernetes-cluster ~]$ kubectl get rs
NAME DESIRED CURRENT READY AGE
nginx-deployment-77d8468669 2 2 2 69s

[opc@kubernetes-cluster ~]$ kubectl get pod


NAME READY STATUS RESTARTS AGE
nginx-deployment-77d8468669-97jkr 1/1 Running 0 2m49s
nginx-deployment-77d8468669-xzd7v 1/1 Running 0 2m49s
[opc@kubernetes-cluster ~]$
Delete a pod
[opc@kubernetes-cluster ~]$ kubectl delete pod nginx-deployment-
77d8468669-97jkr
pod "nginx-deployment-77d8468669-97jkr" deleted

in a duplicate session
[opc@kubernetes-cluster ~]$ kubectl get pods -w

[opc@kubernetes-cluster ~]$ kubectl get pods


NAME READY STATUS RESTARTS AGE
nginx-deployment-77d8468669-tp9t4 1/1 Running 0 12s
nginx-deployment-77d8468669-xzd7v 1/1 Running 0 4m9s
[opc@kubernetes-cluster ~]$

Now services.
It basically acts as an LB and the backend set which has the Ips, those are
being managed as labels/selectors(just like hostnames in Linux).

There are various ways on how external users can connect to Kubernetes
deployment.
Loadbalancer mode-external users from public can connect.
Nodeport mode- users who have access to VCNs/VPCs can connect to
Kubernetes application.

Workflow
Deployment>POD>Service>Load balancing or exposing it

[opc@kubernetes-cluster ~]$ minikube status


minikube
type: Control Plane
host: Running
kubelet: Running
apiserver: Running
kubeconfig: Configured

[opc@kubernetes-cluster ~]$
[opc@kubernetes-cluster ~]$ kubectl get all
NAME READY STATUS RESTARTS AGE
pod/nginx-deployment-77d8468669-tp9t4 1/1 Running 1 (27h ago) 27h
pod/nginx-deployment-77d8468669-xzd7v 1/1 Running 1 (27h ago) 27h

NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE


service/kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 47h

NAME READY UP-TO-DATE AVAILABLE AGE


deployment.apps/nginx-deployment 2/2 2 2 27h

NAME DESIRED CURRENT READY AGE


replicaset.apps/nginx-deployment-77d8468669 2 2 2 27h
[opc@kubernetes-cluster ~]$

Delete all the deployment except one

[opc@kubernetes-cluster ~]$ kubectl delete deploy nginx-deployment


deployment.apps "nginx-deployment" deleted
[opc@kubernetes-cluster ~]$ kubectl get all
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 47h
[opc@kubernetes-cluster ~]$

Let us create a deployment

As of now zero
[opc@kubernetes-cluster ~]$ kubectl get deploy
No resources found in default namespace.
[opc@kubernetes-cluster ~]$ kubectl get pods
No resources found in default namespace.
[opc@kubernetes-cluster ~]$

[opc@kubernetes-cluster ~]$ kubectl apply -f deployment.yaml


deployment.apps/nginx-deployment created
[opc@kubernetes-cluster ~]$ kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx-deployment-cb5c956b9-58v87 1/1 Running 0 5s
nginx-deployment-cb5c956b9-njlcd 1/1 Running 0 5s
[opc@kubernetes-cluster ~]$

[opc@kubernetes-cluster ~]$ kubectl get pods -o wide


NAME READY STATUS RESTARTS AGE IP NODE
NOMINATED NODE READINESS GATES
nginx-deployment-cb5c956b9-58v87 1/1 Running 0 28s 10.244.0.14
minikube <none> <none>
nginx-deployment-cb5c956b9-njlcd 1/1 Running 0 28s 10.244.0.13
minikube <none> <none>
[opc@kubernetes-cluster ~]$

[opc@kubernetes-cluster ~]$ kubectl get pods -v=7


I0515 14:44:02.572154 26253 loader.go:395] Config loaded from file:
/home/opc/.kube/config
I0515 14:44:02.573317 26253 cert_rotation.go:137] Starting client certificate
rotation controller
I0515 14:44:02.579108 26253 round_trippers.go:463] GET
https://192.168.49.2:8443/api/v1/namespaces/default/pods?limit=500
I0515 14:44:02.579139 26253 round_trippers.go:469] Request Headers:
I0515 14:44:02.579161 26253 round_trippers.go:473] Accept:
application/json;as=Table;v=v1;g=meta.k8s.io,application/json;as=Table;v=v1
beta1;g=meta.k8s.io,application/json
I0515 14:44:02.579179 26253 round_trippers.go:473] User-Agent:
kubectl/v1.30.0 (linux/amd64) kubernetes/7c48c2b
I0515 14:44:02.589061 26253 round_trippers.go:574] Response Status: 200
OK in 9 milliseconds
NAME READY STATUS RESTARTS AGE
nginx-deployment-cb5c956b9-58v87 1/1 Running 0 2m20s
nginx-deployment-cb5c956b9-njlcd 1/1 Running 0 2m20s
[opc@kubernetes-cluster ~]$

[opc@kubernetes-cluster ~]$ kubectl get pods -o wide


NAME READY STATUS RESTARTS AGE IP NODE
NOMINATED NODE READINESS GATES
nginx-deployment-cb5c956b9-58v87 1/1 Running 0 28s 10.244.0.14
minikube <none> <none>
nginx-deployment-cb5c956b9-njlcd 1/1 Running 0 28s 10.244.0.13
minikube <none> <none>
go inside the container
docker@minikube:~$ curl -L http://10.244.0.13:80
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to


<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>


</body>
</html>
docker@minikube:~$

As you can see that I am able to see the traffic

Now, come out of the pod


[opc@kubernetes-cluster ~]$ curl -L http://10.244.0.13:80

We are not able to connect. So to outside world, it is not exposed.

Now comes the play for service.


Nodeport if I create it will be accessible within the Kubernetes cluster and
loadbalancer will allow it from outside/browser as well.

Ingress controller is the commercial one Load balancer which has features
such as sticky sessions, path based routing.

Ingress controller>>ingress

You might also like