Sunday, March 3, 2019

Kubernetes and Containers

I was reading about containers and Kubernetes from the past few months. Did kubernetes cluster setup on google cloud. today when i tried to setup minikube on a Centos VM on laptop, ran into some issues.

VM OS version: CentOS Linux release 7.5.1804
Cores: 4
RAM: 24GB
Docker version: 18.09.0
minikube version: 0.33.1


[root@localhost ~]# yum list|grep libvirt-daemon-kvm
Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
libvirt-daemon-kvm.x86_64                 4.5.0-10.el7_6.3             updates

[root@localhost ~]# curl -Lo minikube-machine-driver-kvm2 https://storage.googleapis.com/minikube/releases/latest/docker-machine-driver-kvm2
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 36.6M  100 36.6M    0     0  1455k      0  0:00:25  0:00:25 --:--:-- 1527k

curl -Lo minikube https://storage.googleapis.com/minikube/releases/v0.33.1/minikube-linux-amd64
[root@localhost ~]# curl -Lo minikube https://storage.googleapis.com/minikube/releases/v0.33.1/minikube-linux-amd64
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 37.3M  100 37.3M    0     0  1482k      0  0:00:25  0:00:25 --:--:-- 1534k
[root@localhost ~]# chmod +x minikube
[root@localhost ~]# cp minikube /usr/local/bin/
rm[root@localhost ~]# rm minikube

[root@localhost ~]# minikube start vm-driver kvm2
There is a newer version of minikube available (v0.34.1).  Download it here:
https://github.com/kubernetes/minikube/releases/tag/v0.34.1

To disable this notification, run the following:
minikube config set WantUpdateNotification false
Starting local Kubernetes v1.10.0 cluster...
Starting VM...
Downloading Minikube ISO
 29.84 MB / 170.18 MB [=======>----------------------------------]  17.54% 1m33s

Please enter your response [Y/n]: [root@localhost ~]# minikube start
Starting local Kubernetes v1.10.0 cluster...
Starting VM...
E0303 20:37:36.865099    7876 start.go:168] Error starting host: Error creating host: Error executing step: Running precreate checks.
: VBoxManage not found. Make sure VirtualBox is installed and VBoxManage is in the path.

 Retrying.
E0303 20:37:36.865477    7876 start.go:174] Error starting host:  Error creating host: Error executing step: Running precreate checks.
: VBoxManage not found. Make sure VirtualBox is installed and VBoxManage is in the path
================================================================================
An error has occurred. Would you like to opt in to sending anonymized crash
information to minikube to help prevent future errors?
To opt out of these messages, run the command:
        minikube config set WantReportErrorPrompt false
================================================================================
Please enter your response [Y/n]: [root@localhost ~]# minikube start
Starting local Kubernetes v1.10.0 cluster...
Starting VM...
E0303 20:40:35.089182    8027 start.go:168] Error starting host: Error creating host: Error executing step: Running precreate checks.
: VBoxManage not found. Make sure VirtualBox is installed and VBoxManage is in the path.

 Retrying.
E0303 20:40:35.093199    8027 start.go:174] Error starting host:  Error creating host: Error executing step: Running precreate checks.
: VBoxManage not found. Make sure VirtualBox is installed and VBoxManage is in the path
================================================================================
An error has occurred. Would you like to opt in to sending anonymized crash
information to minikube to help prevent future errors?
To opt out of these messages, run the command:
        minikube config set WantReportErrorPrompt false
================================================================================
Please enter your response [Y/n]: n
[root@localhost ~]# minikube start  --vm-driver kvm2
Starting local Kubernetes v1.10.0 cluster...
Starting VM...
E0303 20:42:38.130978    8140 start.go:168] Error starting host: Error creating new host: dial tcp: missing address.

 Retrying.
E0303 20:42:38.131853    8140 start.go:174] Error starting host:  Error creating new host: dial tcp: missing address
================================================================================
An error has occurred. Would you like to opt in to sending anonymized crash
information to minikube to help prevent future errors?
To opt out of these messages, run the command:
        minikube config set WantReportErrorPrompt false
================================================================================
Please enter your response [Y/n]: n


minikube --vm-driver none start

[root@localhost ~]# minikube start --vm-driver none
Starting local Kubernetes v1.13.2 cluster...
Starting VM...
Getting VM IP address...
Moving files into cluster...
Downloading kubeadm v1.13.2
Downloading kubelet v1.13.2
Finished Downloading kubeadm v1.13.2
Finished Downloading kubelet v1.13.2
Setting up certs...
Connecting to cluster...
Setting up kubeconfig...
Stopping extra container runtimes...
Starting cluster components...
Verifying kubelet health ...
Verifying apiserver health ...
Kubectl is now configured to use the cluster.
===================
WARNING: IT IS RECOMMENDED NOT TO RUN THE NONE DRIVER ON PERSONAL WORKSTATIONS
        The 'none' driver will run an insecure kubernetes apiserver as root that may leave the host vulnerable to CSRF attacks

When using the none driver, the kubectl config and credentials generated will be root owned and will appear in the root home directory.
You will need to move the files to the appropriate location and then set the correct permissions.  An example of this is below:

        sudo mv /root/.kube $HOME/.kube # this will write over any previous configuration
        sudo chown -R $USER $HOME/.kube
        sudo chgrp -R $USER $HOME/.kube

        sudo mv /root/.minikube $HOME/.minikube # this will write over any previous configuration
        sudo chown -R $USER $HOME/.minikube
        sudo chgrp -R $USER $HOME/.minikube

This can also be done automatically by setting the env var CHANGE_MINIKUBE_NONE_USER=true
Loading cached images from config file.


Everything looks great. Please enjoy minikube!

[root@localhost ~]# kubectl config view
apiVersion: v1
clusters:
- cluster:
    certificate-authority: /root/.minikube/ca.crt
    server: https://192.168.213.4:8443
  name: minikube
contexts:
- context:
    cluster: minikube
    user: minikube
  name: minikube
current-context: minikube
kind: Config
preferences: {}
users:
- name: minikube
  user:
    client-certificate: /root/.minikube/client.crt
    client-key: /root/.minikube/client.key

[root@localhost ~]# kubectl run hello-minikube --image=k8s.gcr.io/echoserver:1.10 --port=8080
deployment "hello-minikube" created
[root@localhost ~]# kubectl expose deployment hello-minikube --type=NodePort
service "hello-minikube" exposed
[root@localhost ~]# kubectl get pod
NAME                              READY     STATUS              RESTARTS   AGE
hello-minikube-6fd785d459-nkz2f   0/1       ContainerCreating   0          32s
[root@localhost ~]# kubectl get pod
NAME                              READY     STATUS    RESTARTS   AGE
hello-minikube-6fd785d459-nkz2f   1/1       Running   0          40s
[root@localhost ~]# curl $(minikube service hello-minikube --url)


Hostname: hello-minikube-6fd785d459-nkz2f

Pod Information:
        -no pod information available-

Server values:
        server_version=nginx: 1.13.3 - lua: 10008

Request Information:
        client_address=172.17.0.1
        method=GET
        real path=/
        query=
        request_version=1.1
        request_scheme=http
        request_uri=http://192.168.213.4:8080/

Request Headers:
        accept=*/*
        host=192.168.213.4:31504
        user-agent=curl/7.29.0

Request Body:
        -no body in request-

[root@localhost ~]# kubectl delete services hello-minikube
service "hello-minikube" deleted
[root@localhost ~]# kubectl delete deployment hello-minikube
deployment "hello-minikube" deleted
[root@localhost ~]# minikube stop
Stopping local Kubernetes cluster...
Machine stopped.

In the previous setup, i didn't use kvm. upon investigation found libvirtd missing, installed it.

[root@localhost ~]# yum install libvirt-daemon-kvm qemu-kvm

[root@localhost ~]# systemctl status libvirtd
● libvirtd.service - Virtualization daemon
   Loaded: loaded (/usr/lib/systemd/system/libvirtd.service; enabled; vendor preset: enabled)
   Active: inactive (dead)
     Docs: man:libvirtd(8)
           https://libvirt.org


Now start minikube with kvm2
[root@localhost ~]# minikube start --vm-driver kvm2
Starting local Kubernetes v1.13.2 cluster...
Starting VM...
Skipping kvm2 driver, existing host has none driver.
Getting VM IP address...
Moving files into cluster...
Setting up certs...
Connecting to cluster...
Setting up kubeconfig...
Stopping extra container runtimes...
E0303 21:59:23.991240   22584 start.go:353] Error stopping crio: driver does not support ssh commands
Machine exists, restarting cluster components...
Verifying kubelet health ...
Verifying apiserver health ....
Kubectl is now configured to use the cluster.
Loading cached images from config file.


Everything looks great. Please enjoy minikube!


[root@localhost ~]# kubectl run hello-minikube --image=k8s.gcr.io/echoserver:1.10 --port=8080
deployment "hello-minikube" created
[root@localhost ~]# kubectl expose deployment hello-minikube --type=NodePort
service "hello-minikube" exposed
[root@localhost ~]# kubectl get pod
NAME                              READY     STATUS    RESTARTS   AGE
hello-minikube-6fd785d459-fgrbd   1/1       Running   0          17s
[root@localhost ~]# curl $(minikube service hello-minikube --url)


Hostname: hello-minikube-6fd785d459-fgrbd

Pod Information:
        -no pod information available-

Server values:
        server_version=nginx: 1.13.3 - lua: 10008

Request Information:
        client_address=172.17.0.1
        method=GET
        real path=/
        query=
        request_version=1.1
        request_scheme=http
        request_uri=http://192.168.213.4:8080/

Request Headers:
        accept=*/*
        host=192.168.213.4:31132
        user-agent=curl/7.29.0

Request Body:
        -no body in request-

[root@localhost ~]# kubectl delete services hello-minikube
service "hello-minikube" deleted
[root@localhost ~]# kubectl delete deployment hello-minikube
deployment "hello-minikube" deleted
[root@localhost ~]# minikube stop
Stopping local Kubernetes cluster...
Machine stopped.


No comments:

Post a Comment

Not able to login to a server from putty using ppk file

 If you are not able to login to a Linux server from putty using a ppk file, you can regenerate the file using the below options. Open putty...