Container Orchestration With Kubernetes

Truong, articles
Back

Get help on Container Orchestration on the following frequently asked issues:

Issue 1

I built the python image and created a container ... everything went well but when i visit in the browser 127.0.0.1:5000, I was getting empty response. It turn out that the app was unreachable outside the container.

The problem was I was only binding to the localhost interface. NB: You should be binding to 0.0.0.0 if you want the container to be accessible from outside. After changing:

if __name__ == '__main__':
   app.run()

to

if __name__ == '__main__':
   app.run(host='0.0.0.0')

The app was reachable.

Issue 2

I am getting CreateContainerError message on pod when trying to deploy container to Kubernetes

First please run the command kubectl get po podname in order go get the error description. If the error message is "Error: failed to create containerd container: get apparmor_parser version: exec: "apparmor_parser": executable file not found in $PATH" then quick fix is to run below line in the command prompt

zypper install -t pattern apparmor 

Issue 3

When building docker image, I am receiving "go.mod file not found in current or any parent directory." error message

Adding "RUN go mod init" line before "RUN go build..." into the Dockerfile solves this issue.

Issue 4

I am getting ImagePullBackOff message on pod when trying to deploy container to Kubernetes

Most probably, you entered the container URL incorrectly when deploying the Kubernetes cluster. Please double check your container URL in the Docker Hub. We might be wrong as well. To get a more accurate error message run to check on more details of what is going on:

kubectl describe po PODNAME

Issue 5

Did anyone else get this when trying to label a deployment in exercise 21?: kubectl label deploy nginx-alpine app=nginx tag=alpine --namespace demo

error: 'app' already has a value (nginx-alpine), and --overwrite is false

Are we meant to overwrite it?

Yes, app=nginx is already there, that's why is asking to overwrite, hence you need to add only the tag=alpine Tag or you can add --overwrite==true

Issue 6

I ran port-forward on a pod to view it in the browser, however, it is saying that the site cannot be reached in my browser window. Try this command:

kubectl port-forward --address 0.0.0.0 po/<pod-id> 6111:6111

Take a look at the Vagrantfile. By default, 192.168.50.4 is used as a fixed IP address there so on your local machine, browse 192.168.50.4:6111

Issue 7

When running vagrant up I am receiving the following error:

There was an error while executing VBoxManage, a CLI used by Vagrant for controlling VirtualBox. The command and stderr is shown below.

Command: [“hostonlyif”, “create”]
Stderr: 0%...
Progress state: NS_ERROR_FAILURE
VBoxManage: error: Failed to create the host-only adapter
VBoxManage: error: VBoxNetAdpCtl: Error while adding new interface: failed to open /dev/vboxnetctl: No such file or directory
VBoxManage: error: Details: code NS_ERROR_FAILURE (0x80004005), component HostNetworkInterfaceWrap, interface IHostNetworkInterface
VBoxManage: error: Context: “RTEXITCODE handleCreate(HandlerArg *)” at line 95 of file VBoxManageHostonly.cpp 

You probably have a Mac computer but depending on the OS version it can be solvable or not. Please look at the following forum article for the solution virtualbox.org • View topic - Installation on MacOS 10.15.1 fails . If you are using M1 know that Virtualbox does not support M1.

M1 MacOS instructions* for replacing VirtualBox. This will install k8s

brew install kind

brew install kubectl

kind create cluster

kubectl get no

Issue 8

When running vagrant up I am receiving the following error: Getting this error when trying to run vagrant up command Stderr: VBoxManage.exe: error: Failed to open/create the internal network 'HostInterfaceNetworking-VirtualBox Host-Only Ethernet Adapter #2' (VERR_INTNET_FLT_IF_NOT_FOUND). VBoxManage.exe: error: Failed to attach the network LUN (VERR_INTNET_FLT_IF_NOT_FOUND)

Disable the virtual box network adapters in the control panel (Windows 10), then use the vagrant reload command in Git Bash

Issue 9

wget -q0 IP address is not returning a response

The command is

wget -qO- IP Address

Issue 10

When running vagrant up, I am receiving VERR_INTNET_FLT_IF_NOT_FOUND error message

i solved it doing the following steps: Go to Device Manager on Windows (type "Device Manager" on the botton left lens) Click on Network Adapter and then right click and disable any "VitualBox Host-Only Ethernet Adapter" and re-enable it. now vagrant up should work.

Issue 11

When running docker version, I am receiving an error message: error during connect: In the default daemon configuration on Windows, the docker client must run with elevated priviliges to connect

The error was gone after restarting the PC and signing in to Docker Desktop App https://forums.docker.com/t/restart-docker-service-from-command-line/27331/10

Issue 12

When running vagrant up I got this error: There was an error while executing VBoxManage, a CLI used by Vagrant for controlling VirtualBox. The command and stderr is shown below.

Resolution:

Stderr: VBoxManage: error: VT-x is disabled in the BIOS for all CPU modes (VERR_VMX_MSR_ALL_VMX_DISABLED) Enabling virtualization in the computer BIOS helps.

Issue 13

kubectl cluster-info is returning the following error message: Unable to connect to the server: dial tcp [::1]:8080: connectex: No connection could be made because the target machine actively refused it.

To fix this issue, Run the command below to tell the kubernetes where to find the configuration file: [Environment]::SetEnvironmentVariable("KUBECONFIG", $HOME + ".kube\config", [EnvironmentVariableTarget]::Machine)

Resolution

Please make sure to replace $HOME + ".kube\config" with "/etc/rancher/k3s/k3s.yaml" if you have k3s installed.

Issue 14

There was an error while executing VBoxManage, a CLI used by Vagrant for controlling VirtualBox. The command and stderr is shown below. Stderr: VBoxManage.exe: error: Call to WHvSetupPartition failed: ERROR_SUCCESS (Last=0xc000000d/87) (VERR_NEM_VM_CREATE_FAILED)

Resolution:

You need to go into Windows Features and uncheck BOTH Hyper-V as well as Containers. Reinstalling the latest Virtualbox and rebooting your PC should help.

Issue 15

Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.24/version: dial unix /var/run/docker.sock: connect: permission denied

Resolution

You need to add your user name using sudo usermod -aG docker USER

Issue 16

When running vagrant up I got this error: There was an error while executing VBoxManage, a CLI used by Vagrant for controlling VirtualBox. The command and stderr is shown below.

Resolution:

Stderr: VBoxManage: error: VT-x is not available (VERR_VMX_NO_VMX) This is typically because you don't have VT-x or AMD-V enabled in your BIOS. Or worse yet, your CPU doesn't support virtualization. Following are the instructions if you have the first case.

Issue 17

When running vagrant up I'm getting an error that states that "The box you're attempting to add has no available version that matches the constraints you requested. Please double-check your settings. Also verify that if you specified version constraints, that the provider you wish to use is available for these constraints.

Resolution:

It means that the OpenSuSe version you are trying to pull is not available. In your Vagrantfile comment or remove the line that says config.vm.box_version

Issue 18

If you have Mac OS Catalina or higher and virtualbox is throwing an error: Kernel driver not installed (VERR_VM_DRIVER_NOT_INSTALLED)

Resolution:

It has to do with permissions in your operating system. Please follow this article to fix it.

Issue 19

I encountered this error when running the port-forward for my application. docker: Error response from daemon: Ports are not available: listen tcp 0.0.0.0:6111: bind: address already in use.

Resolution:

Some app is already using port 6111, try picking any other port.

Issue 20

For people who are stuck at Lesson 3 module 16 for not being able to run kubectl commands

Problem:

Running Kubectl commands results in the error:

WARN[2021-07-10T08:42:49.548239687Z] Unable to read /etc/rancher/k3s/k3s.yaml, please start server with --write-kubeconfig-mode to modify kube config permissions error: error loading config file "/etc/rancher/k3s/k3s.yaml": open /etc/rancher/k3s/k3s.yaml: permission denied.

Cause:

kubectl tries to read /etc/rancher/k3s/k3s.yaml and fails.

The kubeconfig file stored at /etc/rancher/k3s/k3s.yaml is used to configure access to the Kubernetes cluster.

Solutions:

Option 1

Change file permission of the file in question

sudo chmod 644 /etc/rancher/k3s/k3s.yaml

Or as the error suggested, start server with --write-kubeconfig-mode to modify kube config permissions.

curl -sfL https://get.k3s.io | sh -s - --write-kubeconfig-mode 644

OR

curl -sfL https://get.k3s.io | K3S_KUBECONFIG_MODE="644" sh -s -

Option 2

Assuming you are in a vagrant box, k3s creates the kubeconfig file as /etc/rancher/k3s/k3s.yaml.

In order to execute kubectl commands without sudo give the vagrant user permissions

sudo chown vagrant.vagrant /etc/rancher/k3s/k3s.yaml

Then if you see the following, you are good to go:

kubectl cluster-info

Kubernetes control plane is running at https://127.0.0.1:6443 CoreDNS is running at https://127.0.0.1:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy Metrics-server is running at https://127.0.0.1:6443/api/v1/namespaces/kube-system/services/https:metrics-server:/proxy

To further debug and diagnose cluster problems, use

kubectl cluster-info dump

Issue 21

Facing issue accessing the virtual box running on windows using vagrant from WSL 2 (Windows Subsystem for Linux). While running the "vagrant up" command, it's showing an error "Warning: Connection refused. Retrying..." even though the actual VM is up and running on Virtual Box.

Resolution:

Restarting doesn't solve this problem.

However, I found a vagrant plugin that’ll ease the job if anyone’s stumbled here in future. It’s called VirtualboxWSL2 and available at

https://github.com/Karandash8/virtualbox_WSL2

After installing this plug-in, it's working. Also, we may need to set the VAGRANT_WSL_WINDOWS_ACCESS_USER_HOME_PATH environment variable to the project directory.

https://www.vagrantup.com/docs/other/wsl

Lab Guide

Refer to this collection named Lab Guide perpared by @AudreyST https://www.notion.so/896ce02bd2d74f369e6a0d08da30bf08?v=65682c8eefce412ba587ee39371f1544

A new tool for teams & individuals that blends everyday work apps into one.

DevOps Tips

Kubectl is the main tool for interacting with kuberenets clusters, as a DevOps person you will be using a lot

kubectl commands, a good way to make things more easier for you is by setting up bash-completion and use bash aliases

Install bash-completion

$ sudo apt-get install bash-completion

or

$ sudo yum install bash-completion

Reload your run and shell

$ type _init_completion

Add bash-completion to bashrc

echo 'source <(kubectl completion bash)' >>~/.bashrc

Setup and alias for kubectl and enable completion for it:

echo 'alias k=kubectl' >>~/.bashrc
echo 'complete -F __start_kubectl k' >>~/.bashrc

Here is the example of the usage. It's mush shorter than typing kubectl everytime!

k get po
k get svc -n demo

Solution For Windows With Ubuntu Errors

Source: https://sites.google.com/view/opensuse-issues/

© TruongIdeas & Feedback