[root@k8s-master-node1 ~]# kubectl get nodes
The connection to the server apiserver.cluster.local:6443 was refused - did you specify the right host or port?
报错1:apiserver.cluster.local:6443 的连接被拒绝
查看服务状态
[root@k8s-master-node1 ~]# systemctl status kubelet
● kubelet.service - kubelet: The Kubernetes Node Agent
Loaded: loaded (/usr/lib/systemd/system/kubelet.service; enabled; vendor preset: disabled)
Drop-In: /usr/lib/systemd/system/kubelet.service.d
└─10-kubeadm.conf, 11-cgroup.conf
Active: active (running) since Tue 2023-10-17 15:48:47 CST; 8min ago
[root@k8s-master-node1 ~]# systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
Active: active (running) since Tue 2023-10-17 15:42:29 CST; 15min ago
Docs: https://docs.docker.com
日志报错
[root@k8s-master-node1 ~]# tail -f /var/log/messages
Oct 17 15:56:32 k8s-master-node1 kubelet: E1017 15:56:32.843485 9392 pod_workers.go:747] "Error syncing pod, skipping" err="failed to "StartContainer" for "kube-apiserver" with CrashLoopBackOff: "back-off 5m0s restarting failed container=kube-apiserver pod=kube-apiserver-k8s-master-node1_kube-system(834e34c21cf001993a4bf8da41841c6c)"" pod="kube-system/kube-apiserver-k8s-master-node1" podUID=834e34c21cf001993a4bf8da41841c6c
Oct 17 15:56:32 k8s-master-node1 kubelet: E1017 15:56:32.941662 9392 kubelet.go:2407] "Error getting node" err="node "k8s-master-node1" not found"
Oct 17 15:56:33 k8s-master-node1 kubelet: E1017 15:56:33.042258 9392 kubelet.go:2407] "Error getting node" err="node "k8s-master-node1" not found"
Oct 17 15:56:33 k8s-master-node1 kubelet: E1017 15:56:33.142402 9392 kubelet.go:2407] "Error getting node" err="node "k8s-master-node1" not found"
Oct 17 15:56:33 k8s-master-node1 kubelet: E1017 15:56:33.243163 9392 kubelet.go:2407] "Error getting node" err="node "k8s-master-node1" not found"
解决1:
kube-apiserver.yaml文件被更改,原文件内容如下
[root@k8s-master-node1 ~]# cat /etc/kubernetes/manifests/kube-apiserver.yaml
apiVersion: v1
kind: Pod
metadata:
annotations:
kubeadm.kubernetes.io/kube-apiserver.advertise-address.endpoint: 192.168.60.250:6443
creationTimestamp: null
labels:
component: kube-apiserver
tier: control-plane
name: kube-apiserver
namespace: kube-system
spec:
containers:
- command:
- kube-apiserver
- --advertise-address=192.168.60.250
- --allow-privileged=true
- --authorization-mode=Node,RBAC
- --client-ca-file=/etc/kubernetes/pki/ca.crt
- --enable-admission-plugins=NodeRestriction
- --enable-bootstrap-token-auth=true
- --etcd-cafile=/etc/kubernetes/pki/etcd/ca.crt
- --etcd-certfile=/etc/kubernetes/pki/apiserver-etcd-client.crt
- --etcd-keyfile=/etc/kubernetes/pki/apiserver-etcd-client.key
- --etcd-servers=https://127.0.0.1:2379
- --event-ttl=720h
- --kubelet-client-certificate=/etc/kubernetes/pki/apiserver-kubelet-client.crt
- --kubelet-client-key=/etc/kubernetes/pki/apiserver-kubelet-client.key
- --kubelet-preferred-address-types=InternalIP,ExternalIP,Hostname
- --proxy-client-cert-file=/etc/kubernetes/pki/front-proxy-client.crt
- --proxy-client-key-file=/etc/kubernetes/pki/front-proxy-client.key
- --requestheader-allowed-names=front-proxy-client
- --requestheader-client-ca-file=/etc/kubernetes/pki/front-proxy-ca.crt
- --requestheader-extra-headers-prefix=X-Remote-Extra-
- --requestheader-group-headers=X-Remote-Group
- --requestheader-username-headers=X-Remote-User
- --secure-port=6443
- --service-account-issuer=https://kubernetes.default.svc.cluster.local
- --service-account-key-file=/etc/kubernetes/pki/sa.pub
- --service-account-signing-key-file=/etc/kubernetes/pki/sa.key
- --service-cluster-ip-range=10.96.0.0/16
- --service-node-port-range=1024-65535
- --tls-cert-file=/etc/kubernetes/pki/apiserver.crt
- --tls-private-key-file=/etc/kubernetes/pki/apiserver.key
image: k8s.gcr.io/kube-apiserver:v1.22.1
imagePullPolicy: IfNotPresent
livenessProbe:
failureThreshold: 8
httpGet:
host: 192.168.60.250
path: /livez
port: 6443
scheme: HTTPS
initialDelaySeconds: 10
periodSeconds: 10
timeoutSeconds: 15
name: kube-apiserver
readinessProbe:
failureThreshold: 3
httpGet:
host: 192.168.60.250
path: /readyz
port: 6443
scheme: HTTPS
periodSeconds: 1
timeoutSeconds: 15
resources:
requests:
cpu: 250m
startupProbe:
failureThreshold: 24
httpGet:
host: 192.168.60.250
path: /livez
port: 6443
scheme: HTTPS
initialDelaySeconds: 10
periodSeconds: 10
timeoutSeconds: 15
volumeMounts: - mountPath: /etc/ssl/certs
name: ca-certs
readOnly: true - mountPath: /etc/pki
name: etc-pki
readOnly: true - mountPath: /etc/kubernetes/pki
name: k8s-certs
readOnly: true - mountPath: /etc/localtime
name: localtime
readOnly: true
hostNetwork: true
priorityClassName: system-node-critical
securityContext:
seccompProfile:
type: RuntimeDefault
volumes:
- hostPath:
path: /etc/ssl/certs
type: DirectoryOrCreate
name: ca-certs - hostPath:
path: /etc/pki
type: DirectoryOrCreate
name: etc-pki - hostPath:
path: /etc/kubernetes/pki
type: DirectoryOrCreate
name: k8s-certs - hostPath:
path: /etc/localtime
type: File
name: localtime
status: {}
日志恢复
[root@k8s-master-node1 ~]# tail -f /var/log/messages
Oct 17 16:10:38 k8s-master-node1 docker-compose: harbor-portal | 172.18.0.10 - - [17/Oct/2023:08:10:38 +0000] "GET / HTTP/1.1" 200 1167 "-" "curl/7.78.0"
Oct 17 16:10:38 k8s-master-node1 docker-compose: nginx | 127.0.0.1 - "GET / HTTP/1.1" 200 1167 "-" "curl/7.78.0" 0.000 0.001 .
Oct 17 16:10:42 k8s-master-node1 docker-compose: harbor-portal | 172.18.0.2 - - [17/Oct/2023:08:10:42 +0000] "GET / HTTP/1.1" 200 532 "-" "Go-http-client/1.1"
Oct 17 16:10:42 k8s-master-node1 docker-compose: registry | 172.18.0.2 - - [17/Oct/2023:08:10:42 +0000] "GET / HTTP/1.1" 200 0 "" "Go-http-client/1.1"
Oct 17 16:10:42 k8s-master-node1 docker-compose: registryctl | 172.18.0.2 - - [17/Oct/2023:08:10:42 +0000] "GET /api/health HTTP/1.1" 200 9
验证
[root@k8s-master-node1 ~]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
k8s-master-node1 Ready control-plane,master,worker 16d v1.22.1
k8s-worker-node1 NotReady worker 16d v1.22.1