ubuntu16.04搭建Kubernets集群

1.准备三台物理机(master-1台, node-2台)

 

ip

name

192.168.4.138

master

192.168.4.140

k8s-node

192.168.4.149

tf-serving

 

 

2.修改ubuntu国内镜像源(三台物理机都修改)

   — 我们这里使用阿里云的镜像,修改 /etc/apt/sources.list 为: 

# 全部切换为root用户
$ su - root


# 进入目录修改镜像源
$ vim /etc/apt/sources.list


# 替换镜像源
deb http://mirrors.aliyun.com/ubuntu/ xenial main
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main
 
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main
 
deb http://mirrors.aliyun.com/ubuntu/ xenial universe
deb-src http://mirrors.aliyun.com/ubuntu/ xenial universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
 
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main
deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security universe

 

 

3.禁用swap, 并设置网关, 禁用SELINUX:

# 禁用swap
$ swapoff -a



# 查看防火墙状态:ufw status
# 开启防火墙:ufw enable
# 注:防火墙开启的时候,无法远程使用ssh连接,需要关闭


# 关闭防火墙
$ ufw disable


# 关闭SELINUX
# getenforce     可查询SELINUX状态:Disabled表示关闭
$ setenforce 0      # 临时关闭(不用重启机器)


$ vim /etc/selinux/config
# 写入以下内容,重启机器,一直关闭SELINUX
SELINUX=disabled

 

 

4.三台物理机都安装docker-ce(Ubuntu16.04):

# 如果是root权限,不需要sudo

$ sudo apt-get remove docker docker-engine docker.io $ sudo apt-get update $ sudo apt-get install \ apt-transport-https \ ca-certificates \ curl \ software-properties-common $ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - $ sudo add-apt-repository \ "deb [arch=amd64] https://download.docker.com/linux/ubuntu \ $(lsb_release -cs) \ stable" $ sudo apt-get update $ sudo apt-get install docker-ce $ sudo docker version # 查看docker版本
# 结果

  Client:
  Version: 18.09.7
  API version: 1.39
  Go version: go1.10.8
  Git commit: 2d0083d
  Built: Thu Jun 27 17:56:17 2019
  OS/Arch: linux/amd64
  Experimental: false

 
  

  Server: Docker Engine - Community
  Engine:
  Version: 18.09.7
  API version: 1.39 (minimum version 1.12)
  Go version: go1.10.8
  Git commit: 2d0083d
  Built: Thu Jun 27 17:23:02 2019
  OS/Arch: linux/amd64
  Experimental: false

 

  # 设置docker的开机自启:

  $ sudo systemctl enable docker

 

 

 

5.三个节点都安装:kubelet,kubeadm,kubectl

# 如果有VPN,可以使用这个方法安装,因为需要访问google:

$ apt-get update && apt-get install -y apt-transport-https curl
$ 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 https://apt.kubernetes.io/ kubernetes-xenial main 
EOF
$ apt-get update
$ apt-get install -y kubelet kubeadm kubectl
$ apt-mark hold kubelet kubeadm kubectl





# 如果没有VPN,则使用aiyun的软件源安装:

$ apt-get update && apt-get install -y apt-transport-https
$ curl https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | apt-key add - 
$ cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main
EOF
$ apt-get update
$ apt-get install -y kubelet kubeadm kubectl

 

 

6.在master节点操作:

6.1 设置网桥: 

$ sudo sysctl net.bridge.bridge-nf-call-iptables=1

# 结果
net.bridge.bridge-nf-call-iptables = 1

 

6.2 重启kubelet:

$ sudo systemctl daemon-reload
$ sudo systemctl restart kubelet

 

6.3 查看当前kubeadm版本号和所需组件:

$ sudo kubeadm version

# 结果
kubeadm version: &version.Info{Major:"1", Minor:"15", GitVersion:"v1.15.0", GitCommit:"e8462b5b5dc2584fdcd18e6bcfe9f1e4d970a529", GitTreeState:"clean", BuildDate:"2019-06-19T16:37:41Z", GoVersion:"go1.12.5", Compiler:"gc", Platform:"linux/amd64"}

 

6.4 查看kubeadm镜像信息:

$ sudo  kubeadm config images list --kubernetes-version=v1.15.0

# 结果

  k8s.gcr.io/kube-apiserver:v1.15.0
  k8s.gcr.io/kube-controller-manager:v1.15.0
  k8s.gcr.io/kube-scheduler:v1.15.0
  k8s.gcr.io/kube-proxy:v1.15.0
  k8s.gcr.io/pause:3.1
  k8s.gcr.io/etcd:3.3.10
  k8s.gcr.io/coredns:1.3.1

 

 

6.5 只是master节点初始化(部署):

# 这一步很关键,由于kubeadm 默认从官网k8s.grc.io下载所需镜像,国内无法访问,因此需要通过–image-repository指定阿里云镜像仓库地址。
 
$ kubeadm init --kubernetes-version=1.15.0 \
--apiserver-advertise-address=192.168.4.138 \
--image-repository registry.aliyuncs.com/google_containers \
--service-cidr=10.1.0.0/16 \
--pod-network-cidr=10.244.0.0/16 \
--ignore-preflight-errors=Swap

初始化结果:

[init] Using Kubernetes version: v1.15.0
[preflight] Running pre-flight checks
        [WARNING IsDockerSystemdCheck]: detected "cgroupfs" as the Docker cgroup driver. The recommended driver is "systemd". Please follow the guide at https://kubernetes.io/docs/setup/cri/
[preflight] Pulling images required for setting up a Kubernetes cluster
[preflight] This might take a minute or two, depending on the speed of your internet connection
[preflight] You can also perform this action in beforehand using 'kubeadm config images pull'
[kubelet-start] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env"
[kubelet-start] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml"
[kubelet-start] Activating the kubelet service
[certs] Using certificateDir folder "/etc/kubernetes/pki"
[certs] Generating "ca" certificate and key
[certs] Generating "apiserver-kubelet-client" certificate and key
[certs] Generating "apiserver" certificate and key
[certs] apiserver serving cert is signed for DNS names [k8smaster-kvm kubernetes kubernetes.default kubernetes.default.svc kubernetes.default.svc.cluster.local] and IPs [10.1.0.1 192.168.4.138]
[certs] Generating "etcd/ca" certificate and key
[certs] Generating "etcd/healthcheck-client" certificate and key
[certs] Generating "etcd/peer" certificate and key
[certs] etcd/peer serving cert is signed for DNS names [k8smaster-kvm localhost] and IPs [192.168.4.138 127.0.0.1 ::1]
[certs] Generating "apiserver-etcd-client" certificate and key
[certs] Generating "etcd/server" certificate and key
[certs] etcd/server serving cert is signed for DNS names [k8smaster-kvm localhost] and IPs [192.168.4.138 127.0.0.1 ::1]
[certs] Generating "front-proxy-ca" certificate and key
[certs] Generating "front-proxy-client" certificate and key
[certs] Generating "sa" key and public key
[kubeconfig] Using kubeconfig folder "/etc/kubernetes"
[kubeconfig] Writing "admin.conf" kubeconfig file
[kubeconfig] Writing "kubelet.conf" kubeconfig file
[kubeconfig] Writing "controller-manager.conf" kubeconfig file
[kubeconfig] Writing "scheduler.conf" kubeconfig file
[control-plane] Using manifest folder "/etc/kubernetes/manifests"
[control-plane] Creating static Pod manifest for "kube-apiserver"
[control-plane] Creating static Pod manifest for "kube-controller-manager"
[control-plane] Creating static Pod manifest for "kube-scheduler"
[etcd] Creating static Pod manifest for local etcd in "/etc/kubernetes/manifests"
[wait-control-plane] Waiting for the kubelet to boot up the control plane as static Pods from directory "/etc/kubernetes/manifests". This can take up to 4m0s
[apiclient] All control plane components are healthy after 20.003828 seconds
[upload-config] Storing the configuration used in ConfigMap "kubeadm-config" in the "kube-system" Namespace
[kubelet] Creating a ConfigMap "kubelet-config-1.15" in namespace kube-system with the configuration for the kubelets in the cluster
[upload-certs] Skipping phase. Please see --upload-certs
[mark-control-plane] Marking the node k8smaster-kvm as control-plane by adding the label "node-role.kubernetes.io/master=''"
[mark-control-plane] Marking the node k8smaster-kvm as control-plane by adding the taints [node-role.kubernetes.io/master:NoSchedule]
[bootstrap-token] Using token: n6gddl.ppaks7gfue22c022
[bootstrap-token] Configuring bootstrap tokens, cluster-info ConfigMap, RBAC Roles
[bootstrap-token] configured RBAC rules to allow Node Bootstrap tokens to post CSRs in order for nodes to get long term certificate credentials
[bootstrap-token] configured RBAC rules to allow the csrapprover controller automatically approve CSRs from a Node Bootstrap Token
[bootstrap-token] configured RBAC rules to allow certificate rotation for all node client certificates in the cluster
[bootstrap-token] Creating the "cluster-info" ConfigMap in the "kube-public" namespace
[addons] Applied essential addon: CoreDNS
[addons] Applied essential addon: kube-proxy

Your Kubernetes control-plane has initialized successfully!

To start using your cluster, you need to run the following as a regular user:

  mkdir -p $HOME/.kube
  sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
  sudo chown $(id -u):$(id -g) $HOME/.kube/config

You should now deploy a pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
  https://kubernetes.io/docs/concepts/cluster-administration/addons/

Then you can join any number of worker nodes by running the following on each as root:

# 重要 kubeadm join
192.168.4.138:6443 --token n6gddl.ppaks7gfue22c022 \ --discovery-token-ca-cert-hash sha256:0d8748615d5e81e08f5b5e239ef1125dcbbf24703b868aeb76b6306823556ad6

注:初始化成功,返回token, token24小时有效

 

6.6 添加api认证(初始化信息里的内容提示)

$ sudo mkdir -p $HOME/.kube
$ sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
$ sudo chown $(id -u):$(id -g) $HOME/.kube/config

 

6.7 查看集群状态

安装flannel network add-on:进行网络通信

kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

输出:

clusterrole.rbac.authorization.k8s.io/flannel created
clusterrolebinding.rbac.authorization.k8s.io/flannel created
serviceaccount/flannel created
configmap/kube-flannel-cfg created
daemonset.extensions/kube-flannel-ds-amd64 created
daemonset.extensions/kube-flannel-ds-arm64 created
daemonset.extensions/kube-flannel-ds-arm created
daemonset.extensions/kube-flannel-ds-ppc64le created
daemonset.extensions/kube-flannel-ds-s390x created

 注:

如果pod状态为Pending、ContainerCreating、ImagePullBackOff 都表明 Pod 没有就绪,Running 才是就绪状态。

如果有pod提示Init:ImagePullBackOff,说明这个pod的镜像在对应节点上拉取失败,我们可以通过 kubectl describe pod 查看 Pod 具体情况,以确认拉取失败的镜像:

root@k8s-master:~# sudo kubectl get pod --all-namespaces
NAMESPACE     NAME                                 READY   STATUS                  RESTARTS   AGE
kube-system   coredns-bccdc95cf-7wv74              0/1     Pending                 0          10m
kube-system   coredns-bccdc95cf-kzpz8              0/1     Pending                 0          10m
kube-system   etcd-k8s-master                      1/1     Running                 0          9m48s
kube-system   kube-apiserver-k8s-master            1/1     Running                 0          10m
kube-system   kube-controller-manager-k8s-master   1/1     Running                 0          9m52s
kube-system   kube-flannel-ds-amd64-brpwk          0/1     Init:ImagePullBackOff   0          9m37s
kube-system   kube-proxy-qkgvn                     1/1     Running                 0          10m
kube-system   kube-scheduler-k8s-master            1/1     Running                 0          10m
root@k8s-master:~# kubectl describe pod kube-flannel-ds-amd64-brpwk --namespace=kube-system

# 结果

...

Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 10m default-scheduler Successfully assigned kube-system/kube-flannel-ds-amd64-brpwk to k8s-master
Warning Failed 2m55s (x2 over 5m34s) kubelet, k8s-master Failed to pull image "quay.io/coreos/flannel:v0.11.0-amd64": rpc error: code = Unknown desc = context canceled
Warning Failed 2m55s (x2 over 5m34s) kubelet, k8s-master Error: ErrImagePull
Normal BackOff 2m43s (x2 over 5m33s) kubelet, k8s-master Back-off pulling image "quay.io/coreos/flannel:v0.11.0-amd64"
Warning Failed 2m43s (x2 over 5m33s) kubelet, k8s-master Error: ImagePullBackOff
Normal Pulling 2m31s (x3 over 10m) kubelet, k8s-master Pulling image "quay.io/coreos/flannel:v0.11.0-amd64"
Normal Pulled 36s kubelet, k8s-master Successfully pulled image "quay.io/coreos/flannel:v0.11.0-amd64"
Normal Created 36s kubelet, k8s-master Created container install-cni
Normal Started 35s kubelet, k8s-master Started container install-cni
Normal Pulled 34s kubelet, k8s-master Container image "quay.io/coreos/flannel:v0.11.0-amd64" already present on machine
Normal Created 34s kubelet, k8s-master Created container kube-flannel
Normal Started 33s kubelet, k8s-master Started container kube-flannel
root@k8s-master:~# docker pull quay.io/coreos/flannel:v0.11.0-amd64

这里看最后events输出内容,可以看到在下载 image 时失败,如果网络质量不好,这种情况是很常见的。我们可以耐心等待,因为 Kubernetes 会重试,我们也可以自己手工执行 docker pull 去下载这个镜像。

root@k8s-master:~# docker pull quay.io/coreos/flannel:v0.11.0-amd64
v0.11.0-amd64: Pulling from coreos/flannel
cd784148e348: Already exists
04ac94e9255c: Already exists
e10b013543eb: Already exists
005e31e443b1: Already exists
74f794f05817: Already exists
Digest: sha256:7806805c93b20a168d0bbbd25c6a213f00ac58a511c47e8fa6409543528a204e
Status: Image is up to date for quay.io/coreos/flannel:v0.11.0-amd64

如果无法从 quay.io/coreos/flannel:v0.11.0-amd64 下载镜像,可以从阿里云或者dockerhub镜像仓库下载,然后改回原来的tag即可:

docker pull registry.cn-hangzhou.aliyuncs.com/kubernetes_containers/flannel:v0.11.0-amd64

docker tag registry.cn-hangzhou.aliyuncs.com/kubernetes_containers/flannel:v0.11.0-amd64 quay.io/coreos/flannel:v0.11.0-amd64

docker rmi registry.cn-hangzhou.aliyuncs.com/kubernetes_containers/flannel:v0.11.0-amd64
root@k8s-master:~# sudo kubectl get pod --all-namespaces
NAMESPACE     NAME                                 READY   STATUS             RESTARTS   AGE
kube-system   coredns-bccdc95cf-7wv74              0/1     CrashLoopBackOff   4          12m
kube-system   coredns-bccdc95cf-kzpz8              0/1     CrashLoopBackOff   4          12m
kube-system   etcd-k8s-master                      1/1     Running            0          11m
kube-system   kube-apiserver-k8s-master            1/1     Running            0          11m
kube-system   kube-controller-manager-k8s-master   1/1     Running            0          11m
kube-system   kube-flannel-ds-amd64-brpwk          1/1     Running            0          11m
kube-system   kube-proxy-qkgvn                     1/1     Running            0          12m
kube-system   kube-scheduler-k8s-master            1/1     Running            0          11m

# 发现Init:ImagePullBackOff   flannel的镜像已经拉取成功了。

 

 

6.8 查看集群状态

$ sudo kubectl get cs

# 结果
NAME                 STATUS    MESSAGE              ERROR
controller-manager   Healthy   ok                   
scheduler            Healthy   ok                   
etcd-0               Healthy   {"health": "true"}

确认个组件都处于healthy状态。

 

(如果集群初始化如果遇到问题,可以使用下面的命令进行清理:)

$ sudo kubeadm reset

# 执行完这个命令之后,报错:
[init] Using Kubernetes version: v1.15.0
[preflight] Running pre-flight checks
      [WARNING IsDockerSystemdCheck]: detected "cgroupfs" as the Docker cgroup driver. The recommended driver is "systemd". Please follow the guide at https://kubernetes.io/docs/setup/cri/
error execution phase preflight: [preflight] Some fatal errors occurred:
      [ERROR DirAvailable--var-lib-etcd]: /var/lib/etcd is not empty
[preflight] If you know what you are doing, you can make a check non-fatal with `--ignore-preflight-errors=...`



# 解决办法:直接删除etcd目录
$ sudo rm -rf /var/lib/etcd

# 再执行:
$ sudo kubeadm reset

   reset之后:

    $ mkdir -p $HOME/.kube                                              
    $ sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
    $ sudo chown $(id -u):$(id -g) $HOME/.kube/config
    # 否则报错(Unable to connect to the server: x509: certificate signed by unknown authority (possibly because of "crypto/rsa: verification error" while trying to verify candidate authority certificate "kubernetes") )

 

 

注:

    root@k8smaster-KVM:~# kubectl get nodes
       The connection to the server 192.168.4.147:6443 was refused - did you specify the right host or port?

   # 解决方法:
    $ sudo -i
    $ swapoff -a
    $ exit
    $ strace -eopenat kubectl version


   # 然后再次查询即可 :kubectl get nodes

 

 

 

 

6.9 查看Pod信息:

$ sudo kubectl get pod --all-namespaces
# 结果显示:
NAMESPACE     NAME                                    READY   STATUS             RESTARTS   AGE
kube-system   coredns-bccdc95cf-jw4rd                 0/1     CrashLoopBackOff   5          11m
kube-system   coredns-bccdc95cf-nz6hf                 0/1     CrashLoopBackOff   5          11m
kube-system   etcd-k8smaster-kvm                      1/1     Running            0          10m
kube-system   kube-apiserver-k8smaster-kvm            1/1     Running            0          10m
kube-system   kube-controller-manager-k8smaster-kvm   1/1     Running            0          10m
kube-system   kube-flannel-ds-amd64-szlxv             1/1     Running            0          6m17s
kube-system   kube-proxy-4qxzk                        1/1     Running            0          11m
kube-system   kube-scheduler-k8smaster-kvm            1/1     Running            0          10m

注:至此,master搭建只能说成功一半,需要解决2个coredns的问题,网上有一些方法,小弟不精,没能掌握;

同时还伴随着出现一个问题:重启机器时,在输入查看Pod信息命令时( $ sudo kubectl get pod --all-namespaces),会报出一个提示:

The connection to the server 192.168.4.138:6443 was refused - did you specify the right host or port?

网上很多方法我都尝试了,没能成功,也许你们可以成功。最后,我尝试了这个命令,同时解决了我俩个问题:

sudo cp /etc/kubernetes/admin.conf $HOME/
sudo chown $(id -u):$(id -g) $HOME/admin.conf
export KUBECONFIG=$HOME/admin.conf (关键一条)

输完这三行命令之后,这两个问题同时解决了,我都惊了!(具体什么原因,我正在学习。)

root@k8smaster-KVM:~# kubectl get pod --all-namespaces
NAMESPACE NAME READY STATUS RESTARTS AGE kube
-system coredns-bccdc95cf-jw4rd 1/1 Running 27 117m kube-system coredns-bccdc95cf-nz6hf 1/1 Running 27 117m kube-system etcd-k8smaster-kvm 1/1 Running 2 116m kube-system kube-apiserver-k8smaster-kvm 1/1 Running 2 117m kube-system kube-controller-manager-k8smaster-kvm 1/1 Running 2 116m kube-system kube-flannel-ds-amd64-szlxv 1/1 Running 2 112m kube-system kube-proxy-4qxzk 1/1 Running 2 117m kube-system kube-scheduler-k8smaster-kvm 1/1 Running 2 116m

 

 

以上方法如果不成功,还有一种我成功的方法:

原来的/etc/resolv.conf文件内只有:nameserver:127.0.0.1,还有软连接;
解决方法:删除conf文件,新建一个一模一样的conf文件

$ sudo rm -rf /etc/resolv.conf
$ sudo touch /etc/resolv.conf
$ sudo vim /etc/resolv.conf

# 内容为:
nameserver 8.8.4.4
nameserver 8.8.8.8

保存,重启reboot即可

至此,master节点操作完成。

 

7. 将node节点加入master节点中,分别在节点物理机上操作:

kubeadm join 192.168.4.138:6443 --token n6gddl.ppaks7gfue22c022 \
> --discovery-token-ca-cert-hash sha256:0d8748615d5e81e08f5b5e239ef1125dcbbf24703b868aeb76b6306823556ad6

遇到的问题:

[preflight] Running pre-flight checks
        [WARNING IsDockerSystemdCheck]: detected "cgroupfs" as the Docker cgroup driver. The recommended driver is "systemd". Pleas                                                                         e follow the guide at https://kubernetes.io/docs/setup/cri/
error execution phase preflight: [preflight] Some fatal errors occurred:
        [ERROR Swap]: running with swap on is not supported. Please disable swap
[preflight] If you know what you are doing, you can make a check non-fatal with `--ignore-preflight-errors=...`

# 解决办法:可能是没有关闭swap,关闭它
$ swapoff -a

 

成功加入master节点:

[preflight] Running pre-flight checks
        [WARNING IsDockerSystemdCheck]: detected "cgroupfs" as the Docker cgroup driver. The recommended driver is "systemd". Pleas                                                                         e follow the guide at https://kubernetes.io/docs/setup/cri/
[preflight] Reading configuration from the cluster...
[preflight] FYI: You can look at this config file with 'kubectl -n kube-system get cm kubeadm-config -oyaml'
[kubelet-start] Downloading configuration for the kubelet from the "kubelet-config-1.15" ConfigMap in the kube-system namespace
[kubelet-start] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml"
[kubelet-start] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env"
[kubelet-start] Activating the kubelet service
[kubelet-start] Waiting for the kubelet to perform the TLS Bootstrap...

This node has joined the cluster:
* Certificate signing request was sent to apiserver and a response was received.
* The Kubelet was informed of the new secure connection details.

Run 'kubectl get nodes' on the control-plane to see this node join the cluster.

 

8. 然后在master节点上查看节点:

$ kubectl get nodes

结果:

root@k8smaster-KVM:~# kubectl get nodes
NAME            STATUS   ROLES    AGE    VERSION
k8smaster-kvm   Ready    master   3h7m   v1.15.0
k8snode-kvm     Ready    <none>   61m    v1.15.0
tfserving-kvm   Ready    <none>   59m    v1.15.0

注:1.STATUS的状态更新有时可能会比较慢,如果没有Ready,等等在查询。

  2. 从节点:kubeadm join的时候,报错:

    [kubelet-check] The HTTP call equal to 'curl -sSL http://localhost:10248/healthz' failed with error: Get http://localhost:10248/healthz: dial tcp 127.0.0.1:10248: connect: connection refused.
    [kubelet-check] It seems like the kubelet isn't running or healthy.
    [kubelet-check] The HTTP call equal to 'curl -sSL http://localhost:10248/healthz' failed with error: Get http://localhost:10248/healthz: dial tcp 127.0.0.1:10248: connect: connection refused.
    [kubelet-check] It seems like the kubelet isn't running or healthy.
    [kubelet-check] The HTTP call equal to 'curl -sSL http://localhost:10248/healthz' failed with error: Get http://localhost:10248/healthz: dial tcp 127.0.0.1:10248: connect: connection refused.
    [kubelet-check] It seems like the kubelet isn't running or healthy.
    [kubelet-check] The HTTP call equal to 'curl -sSL http://localhost:10248/healthz' failed with error: Get http://localhost:10248/healthz: dial tcp 127.0.0.1:10248: connect: connection refused.

解决方法:

sudo vim /etc/systemd/system/kubelet.service.d/10-kubeadm.conf

# 添加
Environment="KUBELET_SYSTEM_PODS_ARGS=--pod-manifest-path=/etc/kubernetes/manifests --allow-privileged=true --fail-swap-on=false"

# 添加完之后在kubeadm join时,还会有端口占用的问题:

  [preflight] Running pre-flight checks
  [WARNING IsDockerSystemdCheck]: detected "cgroupfs" as the Docker cgroup driver. The recommended driver is "systemd". Please follow the guide at https://kubernetes.io/docs/setup/cri/
error execution phase preflight: [preflight] Some fatal errors occurred:
  [ERROR Port-10250]: Port 10250 is in use

 

# 这两个问题的解决办法是:在从节点直接--->重新初始化节点配置,然后在kubeadm join操作即可加入即可:

   $ kubeadm reset

  $ kubeadm join xxxxxxx

 

至此:Ubuntu16.04搭建kubernets集群已经初步搭建完成了,踩坑填坑,还会继续踩,慢慢来吧。

 

参考:十分发感谢 ↓↓↓

https://blog.csdn.net/qq_14845119/article/details/83349471

https://www.codercto.com/a/55625.html

https://blog.csdn.net/Geikon/article/details/94408499

 

转载于:https://www.cnblogs.com/aidenzdly/articles/11202669.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值