I have tried to install Kubernetes on Amazon Linux Machine. I followed a lot of documents and videos in those tutorials they are easily installing kubectl and kops but in my case, I followed the same steps but kubectl is not working for me.
error: The connection to the server localhost:8080 was refused - did you specify the right host or port? I opened all required ports still effecting with the error.
error: The connection to the server localhost:8080 was refused - did you specify the right host or port?
In most cases, this error message is displayed when the kubectl
configuration of your cluster is not set up correctly.
By default ‘kubectl’ configuration file is located in $HOME/.kube/config
and contains the following sections:
Cluster information:
certificates required to connect to the kube-apiserver
clusters:
- cluster:
certificate-authority-data: REDACTED
server: https://10.156.0.3:6443
name: kubernetes
User information:
User certificate
users:
- name: kubernetes-admin
user:
client-certificate-data: REDACTED
client-key-data: REDACTED
Context information:
current context that is used if no context is specified in kubectl
command line
contexts:
- context:
cluster: kubernetes
user: kubernetes-admin
name: kubernetes-admin@kubernetes
current-context: kubernetes-admin@kubernetes
kind: Config
preferences: {}
You can view your current kubectl
configuration using the following command:
kubectl config view
It is possible to have several configuration files that you can add to the environment variable KUBECONFIG
:
export KUBECONFIG=$KUBECONFIG:config-demo:config-demo-2
You can also specify ‘kubectl’ config file in the command line:
kubectl --kubeconfig path/to/kubectl.conf get nodes
You can export your current kubectl
config and use it on another workstation:
kubectl config view --flatten
Please find more information about kubectl
configuration and usage in the following articles:
You can create kubectl
configuration manually or as a part of cluster creation process.
Here is how to create kubectl
configuration for existing kops cluster( link1, link2 ):
# update cluster will do it automatically after cluster creation.
# But we expect that if you're part of a team you might share the KOPS_STATE_STORE
# ASSUMPTION: You have pointed kops to some location where the cluster configurations are stored
# (I have this in my ~/.bash_profile):
export KOPS_STATE_STORE=s3://example-state-store
# Use kops to get the list of clusters
$ kops get clusters
# Export the configuration of the cluster you care about; this will update your ~/.kube/config file, so kubectl knows about it:
$ kops export kubecfg cluster-foo.example.com
# You can now use kubernetes using the kubectl tool:
$ kubectl get nodes
If you created your cluster using kubeadm, kubectl
config is located in /etc/kubernetes/admin.conf
on the master node and you can just copy it to your home directory:
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
1) kubelet is not a service, it's just a binary executable file so there is no any service unit file for it on your system
2) How did you use kops to deploy cluster on aws? I always use the following steps which work for me:
Install awscli
sudo apt-get install python python-pip
sudo python-pip install awscli
Create aws credentials for your admin user (using IAM) and configure your awscli utility to use them
aws configure
Install kops
curl -LO https://github.com/kubernetes/kops/releases/download/$(curl -s https://api.github.com/repos/kubernetes/kops/releases/latest | grep tag_name | cut -d '"' -f 4)/kops-linux-amd64
chmod +x kops-linux-amd64
sudo mv kops-linux-amd64 /usr/local/bin/kops
as well as kubectl
apt-get update && apt-get install -y apt-transport-https
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
deb http://apt.kubernetes.io/ kubernetes-xenial main
EOF
apt-get update
apt-get install -y kubectl
Create s3 bucket
for Kubernetes's storage with some name
aws s3api create-bucket --bucket k8s --region eu-central-1 --create-bucket-configuration LocationConstraint=eu-central-1
aws s3api put-bucket-versioning --region eu-central-1 --bucket k8s --versioning-configuration Status=Enabled
aws s3 ls
Create hosted zone (or subdomain) for Kubernetes cluster in Route53 or use existed one in Route53
, for example test.com
.
Create cluster via kops:
kops create cluster --name=k8s.test.com \
--state=s3://k8s \
--zones=eu-central-1a \
--node-count=2 \
--node-size=t2.small \
--master-count=1 \
--master-size=t2.micro \
--master-zones=eu-central-1a \
--dns-zone=test.com \
--authorization=RBAC \
--yes
wait for a while and check if it's running:
kops validate cluster --name=k8s.test.com --state=s3://k8s