"authenticated as: anonymous Groups that you are in" error when checking kubectl version - kubectl

I am trying to setup the kubectl tool in my machine to remotely manage Kubernetes cluster and also to use Helm. I am trying in Ubuntu 16.04 machine.
I am following the official Kubernetes documentation from the following link,
https://kubernetes.io/docs/tasks/tools/install-kubectl/
I ran the following commands,
sudo apt-get update && sudo apt-get install -y apt-transport-https
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee -a /etc/apt/sources.list.d/kubernetes.list
sudo apt-get update
sudo apt-get install -y kubectl
And after when I am running the 'kubectl version' command to verify the installation , I am getting the following ,
Client Version: version.Info{Major:"1", Minor:"14", GitVersion:"v1.14.1",
GitCommit:"b7394102d6ef778017f2ca4046abbaa23b88c290", GitTreeState:"clean",
BuildDate:"2019-04-08T17:11:31Z", GoVersion:"go1.12.1", Compiler:"gc",
Platform:"linux/amd64"}
Error from server (Forbidden): <html><head><meta http-equiv='refresh'
content='1;url=/login?from=%2Fversion%3Ftimeout%3D32s'/>
<script>window.location.replace('/login?from=%2Fversion%3Ftimeout%3D32s');
</script></head><body style='background-color:white; color:white;'>
Authentication required
<!--
You are authenticated as: anonymous
Groups that you are in:
Permission you need to have (but didn't): hudson.model.Hudson.Read
... which is implied by: hudson.security.Permission.GenericRead
... which is implied by: hudson.model.Hudson.Administer
-->
And also not finding the '~/.kube/config' file in machine.
Why do I get this authentication error when checking the kubectl version?

You have to manually copy .kube/ directory from you cluster node into your local ~/.kube
If you don't have .kube/ on the master node, copy it from /etc/kubernetes/kube.conf
mkdir $HOME/.kube
scp root#<master-public-ip>:/etc/kubernetes/kubelet.conf $HOME/.kube/config
You can also define the filepath of kubeconfig by passing in --kubeconfig parameter, i.e.
kubectl version --kubeconfig ~/.kube/config

Related

docker not installed through yum in user data

this is how my user data looks like, but docker is not installed, when connecting to my ec2 machine:
sudo yum -y install docker
sudo service docker start
sudo docker pull nginx
sudo docker run -d -p 80:80 nginx
what can I do?
When using user-data script you can debug what is happening by ssh connecting to the instance and check the output in cloud-init-output.log.
sudo cat /var/log/cloud-init-output.log
When doing this you'll find an strange error containing:
Jan 29 11:58:25 cloud-init[2970]: __init__.py[WARNING]: Unhandled non-multipart (text/x-not-multipart) userdata: 'sudo yum -y install dock...'
Which means that the default interpreter seems to be python and it's neccesary to start the user-data with #!/bin/bash. (See this other StackOverflow answer)
When changing the user-data to:
#!/bin/bash
sudo yum -y install docker
sudo service docker start
sudo docker pull nginx
sudo docker run -d -p 80:80 nginx
it will be executed as expected and you will find nginx running on your ec2.

How do I uninstall current minio and install specific version of Minio with kubectl?

I have installed minio using the following command.
kubectl krew install minio
Right now I have v4.5.6
How do I install v4.2.10 of minio kubernetes ?
Krew doesn't allow to install any particular version according to docs yet.
So to uninstall run
kubectl krew uninstall minio
Then manually install the version you like with the below command.
wget https://github.com/minio/operator/releases/download/**v4.2.10**/kubectl-minio_**4.2.10**_linux_amd64 -O kubectl-minio
chmod +x kubectl-minio
mv kubectl-minio /usr/local/bin/

Kubernetes configuring master and slave in AWS EC2 instance- getting error while config in slave after giving token

I'm trying to register the master node in slave node. I'm using AWS EC2 instance's i configured docker and Kubernetes in both the instances.
I've followed below steps:
After both instance launched
sudo apt-get update
sudo su -
apt-get install docker.io
ls /etc/docker
cat <<EOF | sudo tee /etc/docker/daemon.json
{
"exec-opts": ["native.cgroupdriver=systemd"],
"log-driver": "json-file",
"log-opts": {
"max-size": "100m"
},
"storage-driver": "overlay2"
}
EOF
systemctl enable docker
systemctl daemon-reload
systemctl restart docker
apt-get update && apt-get install -y apt-transport-https ca-certificates curl && curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg
echo "deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list
apt-get update && apt-get install -y kubelet kubeadm kubectl && apt-mark hold kubelet kubeadm kubectl
=======Master==========
kubeadm init --apiserver-advertise-address=172.31.25.122 --pod-network-cidr=192.168.0.0/16 --ignore-preflight-errors=NumCPU
output:
kubeadm join 172.31.25.122:6443 --token ioewww.jrqwngf1t6ji94yp
--discovery-token-ca-cert-hash sha256:de6116a51a8cae8b128f311d08ba47b2c381bd97403aae8da2a062cf89c83cb3
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
cat $HOME/.kube/config
kubectl apply -f https://docs.projectcalico.org/v3.21/manifests/calico.yaml
======Slave=============
Run Token which you got from the master
sudo su -
kubeadm join 172.31.25.122:6443 --token ioewww.jrqwngf1t6ji94yp \
--discovery-token-ca-cert-hash sha256:de6116a51a8cae8b128f311d08ba47b2c381bd97403aae8da2a062cf89c83cb3
i got below Error
root#slave:~# kubectl get pods
The connection to the server localhost:8080 was refused - did you specify the right host or port?
root#slave:~# kubeadm join 172.31.25.122:6443 --token ioewww.jrqwngf1t6ji94yp
--discovery-token-ca-cert-hash sha256:de6116a51a8cae8b128f311d08ba47b2c381bd97403aae8da2a062cf89c83cb3
[preflight] Running pre-flight checks
[WARNING SystemVerification]: missing optional cgroups: blkio
error execution phase preflight: couldn't validate the identity of the API Server: Get "https://172.31.25.122:6443/api/v1/namespaces/kube-public/configmaps/cluster-info?timeout=10s": net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)
To see the stack trace of this error execute with --v=5 or higher
I'm getting error in slave after giving the token which is generated in master node. could someone please help me on this. how I can overcome this error

can't start minikube in ec2 shows "X Sorry, Kubernetes v1.18.0 requires conntrack to be installed in root's path"

Hi I am trying to start minikube that's why I ran
minikube start --vm-driver=none
But it shows in the console the below lines:
minikube v1.9.2 on Amazon 2 (Xen/amd64)
Using the none driver based on user configuration
X Sorry, Kubernetes v1.18.0 requires conntrack to be installed in root's path
Note that i have installed kubectl minikube and docker.
Please help me to sort out this issues.
I had the same issue. Install 'conntrack' with
sudo apt install conntrack
Then continue to start your minikube:
sudo minikube start --vm-driver=none
Execute following commands
yum install conntrack
start minikube as root
start --driver=none
TL;DR : update minkikube
You need minkikube not older than v1.9.0-beta
It's a known issue
There is a known issue #7179 reproduced in 1.18
Fixed in Pull Request #7180, the latest commit is 1273d4f:
install conntrack for github action integration tests #7180
Minimal minikube ver that contain commit 1273d4f is v1.9.0-beta:
git clone https://github.com/kubernetes/minikube/
cd minikube
git describe 1273d4f8e756ac5eca89d94c449450fb2da21a5a
>v1.9.0-beta.2-16-g1273d4f8e
Explanation of git describe
Explanation of git describe is here
The command is useful for cases such as:
which tag is closest to the commit? (git describe <sha>)
which tag contains commit? (git describe <sha> --contains)
which branch or annotated tag is closest to the commit? (git describe <sha>--all)
On CentOS 7, run following command:
yum install conntrack
And don't forget to have at least 2 (v)CPUs
You need to install conntrack:
apt-get install conntrack -y
and then you can run the minikube start command again
minikube start --vm-driver=none
make sure you do it as a root user or prefix sudo.
If your running ubuntu, make sure you systemd and kubeadm already installed. I found that this resolved for me
sudo apt-get update && sudo apt-get install -y apt-transport-https curl
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
at <<EOF | sudo tee /etc/apt/sources.list.d/kubernetes.list
deb https://apt.kubernetes.io/ kubernetes-xenial main
EOF
sudo apt-get update
sudo apt-get install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl
Reference Links:
https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/install-
https://minikube.sigs.k8s.io/docs/drivers/none/
I use the following command to resolve the issue:
minikube start --vm-driver=docker

AWSEBCLI not reading env vars

I am attempting to run AWSEBCLI inside a docker container. I am passing the access key and security token as env vars as described in the docs under "Configuration Settings and Precedence"
ERROR: CredentialsError - Operation Denied. You appear to have no credentials
Here is my docker file
FROM circleci/golang
ADD . /go/src
WORKDIR /go/src
RUN sudo apt-get -y -qq update --assume-yes
RUN sudo apt-get install python-pip python-dev build-essential --assume-yes
RUN sudo pip install awscli=="1.16.9"
RUN sudo pip install awsebcli=="3.14.4"
RUN echo ${AWS_ACCESS_KEY_ID}
RUN echo ${AWS_SECRET_ACCESS_KEY}
CMD sudo eb deploy Circledocker
The environment defined in your user session and the sudo session are not the same.
RUN echo ${AWS_ACCESS_KEY_ID} -> Works
RUN sudo echo ${AWS_ACCESS_KEY_ID} -> Will not provide you the value.
Take a look at man sudo, the -E flag :
-E, --preserve-env
Indicates to the security policy that the user wishes to preserve their
existing environment variables. The security policy may return an error
if the user does not have permission to preserve the environment.
So this normally works :
sudo -E bash -c 'echo $AWS_ACCESS_KEY_ID'
Try your eb deploy command like this :
sudo -E bash -c 'eb deploy Circledocker'
Hope it helps !