kubectl suddently asking for username - kubernetes

My last deployment pipeline stage on gitlab suddently started asking for username when running "kubectl apply" command to deploy my application in my cluster in GKE (version 1.18.12-gke.1201 and also tested in 1.17). I'm using the imge dtzar/helm-kubectl to run kubectl commands in the pipeline (also tested older versions of this image). This is the log generated when running the stage:
$ kubectl config set-cluster $ITINI_STAG_KUBE_CLUSTER --server="$ITINI_STAG_KUBE_URL" --insecure-skip-tls-verify=true
Cluster "itini-int-cluster" set.
$ kubectl config set-credentials gitlab --token="$ITINI_STAG_KUBE_TOKEN"
User "gitlab" set.
$ kubectl config set-context default --cluster=$ITINI_STAG_KUBE_CLUSTER --user=gitlab
Context "default" created.
$ kubectl config use-context default
Switched to context "default".
$ kubectl apply -f deployment.yml
Please enter Username: error: EOF
I reproduced the same commands locally, and it's working fine.
When running "kubectl version" in the pipeline, this is the output:
Client Version: version.Info{Major:"1", Minor:"19", GitVersion:"v1.19.4", GitCommit:"d360454c9bcd1634cf4cc52d1867af5491dc9c5f", GitTreeState:"clean", BuildDate:"2020-11-11T13:17:17Z", GoVersion:"go1.15.2", Compiler:"gc", Platform:"linux/amd64"}
The connection to the server localhost:8080 was refused - did you specify the right host or port?
When running it locally (with exact same environment variables and tokens configured in the pipeline), this is the output:
Client Version: version.Info{Major:"1", Minor:"20", GitVersion:"v1.20.0", GitCommit:"af46c47ce925f4c4ad5cc8d1fca46c7b77d13b38", GitTreeState:"clean", BuildDate:"2020-12-08T17:59:43Z", GoVersion:"go1.15.5", Compiler:"gc", Platform:"windows/amd64"}
Server Version: version.Info{Major:"1", Minor:"18+", GitVersion:"v1.18.12-gke.1201", GitCommit:"160736941f00e54acb1c0a4647166b6f6eb211d9", GitTreeState:"clean", BuildDate:"2020-12-08T19:38:26Z", GoVersion:"go1.13.15b4", Compiler:"gc", Platform:"linux/amd64"}
What could be causing this problem?

The problem was actually in gitlab. My token variable was marked as "protected" in the gitlab settings, and it was being replaced by an empty string when running the config command. So, the problem was solved by unmarking it as protected.

Related

virtiodev driver access problem in kubernetes and kind but everything works fine in minikube

I’ve run an application to offload the compute on a GPU via the PCI link.
It works fine with Docker and Minikube but I’ve encountered a driver problem with Kubernetes (kubeadm or kind).
I mounted all necessary local folders (and also checked) and gave the privileged access.
In fact, I use the same pod.yaml file for Minikube and Kubeadm or Kind but I get the same problem in Kubeadm and Kind.
Error:
kubectl create -f pod.yml
kubectl exec -it pod -- /bin/bash
(inside the Pod)
./myapp
Insuffisient access for file /sys/bus/***_rpmsg/devices/virtio1.dynept-1-1.-1.1/driver_override
cannot bind virtiodev virtio1.dynept-1-1.-1.1 to driver with service dynept-1-1
$ kubectl version
Client Version: version.Info{Major:"1", Minor:"19", GitVersion:"v1.19.1", GitCommit:"206bcadf021e76c27513500ca24182692aabd17e", GitTreeState:"clean", BuildDate:"2020-09-09T11:26:42Z", GoVersion:"go1.15", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"19", GitVersion:"v1.19.1", GitCommit:"206bcadf021e76c27513500ca24182692aabd17e", GitTreeState:"clean", BuildDate:"2020-09-14T07:30:52Z", GoVersion:"go1.15", Compiler:"gc", Platform:"linux/amd64"}
Container runtime: containerd
The application should be running on Kind/Kubeadm as in Minikube
Thanks for your help!

Problem with Krew “Error: flags cannot be placed before plugin name”

I have a local minikube cluster (version: v1.21.0) with kubectl:
Client Version: version.Info{Major:"1", Minor:"20", GitVersion:"v1.20.7", GitCommit:"132a687512d7fb058d0f5890f07d4121b3f0a2e2", GitTreeState:"clean", BuildDate:"2021-05-12T12:40:09Z", GoVersion:"go1.15.12", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"20", GitVersion:"v1.20.7", GitCommit:"132a687512d7fb058d0f5890f07d4121b3f0a2e2", GitTreeState:"clean", BuildDate:"2021-05-12T12:32:49Z", GoVersion:"go1.15.12", Compiler:"gc", Platform:"linux/amd64"}
I installed krew according to the documentation: https://krew.sigs.k8s.io/docs/user-guide/setup/install/
Then, when I try to execute any command this is the result:
Error: flags cannot be placed before plugin name: --cluster
For example:
minikube kubectl krew version
Error: flags cannot be placed before plugin name: --cluster
Why you are running the minikube in command before the kubectl
minikube kubectl krew version
You can set and use the context of K8s using this command
kubectl config use-context CONTEXT_NAME
Using the kubectl only you can access the Krew and install the plugins
kubectl krew install access-matrix
example
kubectl access-matrix
Read more at : https://krew.sigs.k8s.io/docs/user-guide/quickstart/
https://github.com/kubernetes/kubectl/issues/884

Kubernetes - Kubectl version command returns error

MacOs
I just install kubectl via: https://kubernetes.io/docs/tasks/tools/install-kubectl/#install-kubectl-on-macos
MacBook-Air:~ admin$ kubectl version
Client Version: version.Info{Major:"1", Minor:"17", GitVersion:"v1.17.0", GitCommit:"70132b0f130acc0bed193d9ba59dd186f0e634cf", GitTreeState:"clean", BuildDate:"2019-12-07T21:20:10Z", GoVersion:"go1.13.4", Compiler:"gc", Platform:"darwin/amd64"}
The connection to the server localhost:8080 was refused - did you specify the right host or port?
what could be the problem, Any ideas?
kubectl version prints out both the client version and server version. To fetch the server version, it connects to kubernetes api server. You either do not have the cluster installed or have not configured your kubectl properly to communicate with the remote cluster. So it is only printing client version and throwing an error for server version.
Sample output:
# kubectl version
Client Version: version.Info{Major:"1", Minor:"13", GitVersion:"v1.13.5", GitCommit:"2166946f41b36dea2c4626f90a77706f426cdea2", GitTreeState:"clean", BuildDate:"2019-03-25T15:26:52Z", GoVersion:"go1.11.5", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"13", GitVersion:"v1.13.5", GitCommit:"2166946f41b36dea2c4626f90a77706f426cdea2", GitTreeState:"clean", BuildDate:"2019-03-25T15:19:22Z", GoVersion:"go1.11.5", Compiler:"gc", Platform:"linux/amd64"}
You can use kubectl version --client to get only client version.
# kubectl version --client
Client Version: version.Info{Major:"1", Minor:"13", GitVersion:"v1.13.5", GitCommit:"2166946f41b36dea2c4626f90a77706f426cdea2", GitTreeState:"clean", BuildDate:"2019-03-25T15:26:52Z", GoVersion:"go1.11.5", Compiler:"gc", Platform:"linux/amd64"}
As you mentioned you have installed kubectl - command-line tool, which allows you to run commands against Kubernetes clusters. You can use kubectl to deploy applications, inspect and manage cluster resources, and view logs.
However to kubectl could run any command you need to have a cluster.
The most common is Minikube. However, you will need a hypervisor as Virtualbox or Hyperkit.
You also should read about Docker Desktop on Mac.
If you will search for more information you can find that people also using Kubeadm but its not supported on MacOS.
It was mentioned in another StackOverflow question, you can find it here.
Note : kubectl is a command-line tool tool that allows you to run commands against Kubernetes clusters
In order for kubectl to find and access a given kubernetes cluster, it needs kubeconfig file for a given K8s cluster you want to connect with (if you dont have one you can install a local cluster to play with using something like K8s Minikube which will then give you this file to connect to minikube)
If you already have a cluster then check that kubectl is properly configured use kubectl cluster-info command , if it is not you will receive below error log.
$ kubectl cluster-info
To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
The connection to the server localhost:8080 was refused - did you specify the right host or port?
So to connect to a cluster you want work toward using kubectl you need to find kubeconfig file and configure the environment variable to point to it. Meaning if your $HOME/.kube/config file is not already listed in your KUBECONFIG environment variable, fix your KUBECONFIG environment variable by export KUBECONFIG=$KUBECONFIG:$HOME/.kube/config to point to correct kubeconfig file to be used.
Once you have right kubeconfig exported cluster-info command should load the details as below
$ kubectl cluster-info
Kubernetes master is running at https://xx.xx.xx.xx:6443
KubeDNS is running at https://xx.xx.xx.xx:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy

The kubernetes "AVAILABLE" column indicates "0", but the former steps(in Kubernetes guide) are OK

I need to deploy some docker images, and manage them with the Kubernetes.
I followed the tutorial"Interactive Tutorial - Deploying an App"(https://kubernetes.io/docs/tutorials/kubernetes-basics/deploy-app/deploy-interactive/).
But after I typing the command kuberctl get deployments, in the result table, the deployment column shows 0 instead of 1, it's confusing me.
If there is anyone kindly guides me what's going wrong and what shall I do?
The OS is Ubuntu16.04;
The kuberctl version command shows the server and client version informations well.
The docker image is tagged already(a mysql:5.7 image).
devserver:~$ kubectl version    
Client Version: version.Info{Major:"1", Minor:"13", GitVersion:"v1.13.0", GitCommit:"ddf47ac13c1a9483ea035a79cd7c10005ff21a6d", GitTreeState:"clean", BuildDate:"2018-12-03T21:04:45Z", GoVersion:"go1.11.2", Compiler:"gc", Platform:"linux/amd64"}  
Server Version: version.Info{Major:"1", Minor:"10", GitVersion:"v1.10.0", GitCommit:"fc32d2f3698e36b93322a3465f63a14e9f0eaead", GitTreeState:"clean", BuildDate:"2018-03-26T16:44:10Z", GoVersion:"go1.9.3", Compiler:"gc", Platform:"linux/amd64"}
devserver:~$ kubectl get deployments
NAME  DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
ap-mysql   1    1    1       0     1
hello-node  1    1    1       0     1
I expect the answer about the phenomenon and the resolution. And I need to deploy my image on the minikube.
Katacoda uses hosted VM's so sometimes it may be slow to respond to the terminal input.
To verify if any deployment is present you may run kubectl get deployments --all-namespaces.To see what's going on with your deployment you can run kubectl describe DEPLOYMENT_NAME -n NAMESPACE.To inspect a pod you can do the same kubectl describe POD_NAME -n NAMESPACE.

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

I just finished installing kubectl via Ubuntu 64 (Linux).
I followed the online Kubernetes guide, but I've had an error with the host. After the first step (install kubectl), when I checked the kubectl version, this was the message (I didn't yet install and deploy the minikube because I've not the connection according to this problem):
root#ubuntu:~# kubectl version
Client Version: version.Info{Major:"1", Minor:"13", GitVersion:"v1.13.1", GitCommit:"eec55b9ba98609a46fee712359c7b5b365bdd920", GitTreeState:"clean", BuildDate:"2018-12-13T10:39:04Z", GoVersion:"go1.11.2", Compiler:"gc", Platform:"linux/amd64"}
The connection to the server localhost:8080 was refused - did you specify the right host or port?
Does someone have the same problem? How can I fix it?
The reason behind that is kubectl version prints Client Version and Server Version (kubernetes version) both. When you just install kubectl it is just Kubernetes client. If you have kubernetes cluster installed, it will print both kubectl version and kubernetes version.
If you want to just want to print client version, then use following command:
kubectl version --client=true
The error meant kubectl tried to contact the kubernetes server to get its version but couldn't connect. Are you specifying the right host or port to connect to the kubernetes server.
The reason behind the error is you have not installed kubernetes cluster on you mac. You just installed kubectl which is just a client to access kubernetes cluster. Once you install the kubernetes cluster the output of kubectl version will be like:
[root#ip-10-0-1-138 centos]# kubectl version
Client Version: version.Info{Major:"1", Minor:"13", GitVersion:"v1.13.1",
GitCommit:"eec55b9ba98609a46fee712359c7b5b365bdd920", GitTreeState:"clean", BuildDate:"2018-12-13T10:39:04Z", GoVersion:"go1.11.2", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"10", GitVersion:"v1.10.3", GitCommit:"2bba0127d85d5a46ab4b778548be28623b32d0b0", GitTreeState:"clean", BuildDate:"2018-05-21T09:05:37Z", GoVersion:"go1.9.3", Compiler:"gc", Platform:"linux/amd64"}
If you want to install the complete kubernetes cluster on mac, please try minikube to install cluster locally.
This happens when Kubectl command cannot find the config file inside the user's .kube folder. Here are the steps that you will need for your user:
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
Or if you are the root user:
export KUBECONFIG=/etc/kubernetes/admin.conf