删除Kubernetes并在master和node上重新安装后,我无法再安装NGINX Ingress Controller以正常工作。
首先,要删除Kubernetes,我已经做了:
# On Master
k delete namespace,service,job,ingress,serviceaccounts,pods,deployment,services --all
k delete node k8s-node-0
sudo kubeadm reset
sudo systemctl stop kubelet
sudo apt-get purge kubeadm kubectl kubelet kubernetes-cni kube* -y
sudo apt-get autoremove -y
sudo rm -rf ~/.kube /etc/cni
# On Node
sudo kubeadm reset
sudo systemctl stop kubelet
sudo apt-get purge kubeadm kubectl kubelet kubernetes-cni kube* -y
sudo apt-get autoremove -y
sudo rm -rf ~/.kube
然后,要重新安装所有的东西,我已经做了:
# On Master
sudo apt install -y kubelet kubeadm kubectl
sudo kubeadm init
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
kubectl apply -f https://docs.projectcalico.org/v3.14/manifests/calico.yaml
# On Node
sudo apt install -y kubelet kubeadm kubectl
sudo kubeadm join 10.0.8.135:6443 --token 31xags.h9mr5dz6ncn632uv --discovery-token-ca-cert-hash sha256:c6b479e2130799a4e4d41c4a02dab54eedc431806171b92f4bbc1978d84bd91d
然后安装NGINX入口控制器:
git clone https://github.com/nginxinc/kubernetes-ingress.git
cd kubernetes-ingress/deployments
k apply -f common/ns-and-sa.yaml
k apply -f rbac/rbac.yaml
k apply -f common/default-server-secret.yaml
k apply -f common/nginx-config.yaml
k apply -f deployment/nginx-ingress.yaml
k apply -f daemon-set/nginx-ingress.yaml
然后当我执行k get all -n nginx-ingress
时,我得到了:
NAME READY STATUS RESTARTS AGE
pod/nginx-ingress-2thp4 0/1 CrashLoopBackOff 7 14m
NAME DESIRED CURRENT READY UP-TO-DATE AVAILABLE NODE SELECTOR AGE
daemonset.apps/nginx-ingress 1 1 0 1 0 <none> 14m
以及细节k describe pods nginx-ingress-2thp4 -n nginx-ingress
:
Name: nginx-ingress-2thp4
Namespace: nginx-ingress
Priority: 0
Node: k8s-node-0/10.0.8.66
Start Time: Mon, 28 Sep 2020 15:22:01 +0700
Labels: app=nginx-ingress
controller-revision-hash=646bf8d696
pod-template-generation=1
Annotations: cni.projectcalico.org/podIP: 192.168.11.198/32
cni.projectcalico.org/podIPs: 192.168.11.198/32
Status: Running
IP: 192.168.11.198
IPs:
IP: 192.168.11.198
Controlled By: DaemonSet/nginx-ingress
Containers:
nginx-ingress:
Container ID: docker://175d13f95564d98c06af5514b0519a035e5ee95872bb428fa94c9c2bfc6776a5
Image: nginx/nginx-ingress:edge
Image ID: docker-pullable://nginx/nginx-ingress@sha256:fdb07d0a639d0f2c761b4c5a93f6d5063b972b8ae33252bb7755bb5fb6da4fda
Ports: 80/TCP, 443/TCP, 8081/TCP
Host Ports: 80/TCP, 443/TCP, 0/TCP
Args:
-nginx-configmaps=$(POD_NAMESPACE)/nginx-config
-default-server-tls-secret=$(POD_NAMESPACE)/default-server-secret
State: Waiting
Reason: CrashLoopBackOff
Last State: Terminated
Reason: Error
Exit Code: 255
Started: Mon, 28 Sep 2020 15:33:09 +0700
Finished: Mon, 28 Sep 2020 15:33:09 +0700
Ready: False
Restart Count: 7
Readiness: http-get http://:readiness-port/nginx-ready delay=0s timeout=1s period=1s #success=1 #failure=3
Environment:
POD_NAMESPACE: nginx-ingress (v1:metadata.namespace)
POD_NAME: nginx-ingress-2thp4 (v1:metadata.name)
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from nginx-ingress-token-j9hjm (ro)
Conditions:
Type Status
Initialized True
Ready False
ContainersReady False
PodScheduled True
Volumes:
nginx-ingress-token-j9hjm:
Type: Secret (a volume populated by a Secret)
SecretName: nginx-ingress-token-j9hjm
Optional: false
QoS Class: BestEffort
Node-Selectors: <none>
Tolerations: node.kubernetes.io/disk-pressure:NoSchedule op=Exists
node.kubernetes.io/memory-pressure:NoSchedule op=Exists
node.kubernetes.io/not-ready:NoExecute op=Exists
node.kubernetes.io/pid-pressure:NoSchedule op=Exists
node.kubernetes.io/unreachable:NoExecute op=Exists
node.kubernetes.io/unschedulable:NoSchedule op=Exists
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 15m default-scheduler Successfully assigned nginx-ingress/nginx-ingress-2thp4 to k8s-node-0
Normal Pulled 15m kubelet Successfully pulled image "nginx/nginx-ingress:edge" in 9.106863831s
Normal Pulled 15m kubelet Successfully pulled image "nginx/nginx-ingress:edge" in 3.626387366s
Normal Pulled 14m kubelet Successfully pulled image "nginx/nginx-ingress:edge" in 3.839665529s
Normal Created 14m (x4 over 15m) kubelet Created container nginx-ingress
Normal Started 14m (x4 over 15m) kubelet Started container nginx-ingress
Normal Pulled 14m kubelet Successfully pulled image "nginx/nginx-ingress:edge" in 3.846965585s
Normal Pulling 13m (x5 over 15m) kubelet Pulling image "nginx/nginx-ingress:edge"
Warning BackOff 14s (x70 over 15m) kubelet Back-off restarting failed container
和日志k logs nginx-ingress -n nginx-ingress
:
I0928 08:38:16.776841 1 main.go:245] Starting NGINX Ingress controller Version= GitCommit=
W0928 08:38:16.797787 1 main.go:284] The '-use-ingress-class-only' flag will be deprecated and has no effect on versions of kubernetes >= 1.18.0. Processing ONLY resources that have the 'ingressClassName' field in Ingress equal to the class.
F0928 08:38:16.802335 1 main.go:288] Error when getting IngressClass nginx: ingressclasses.networking.k8s.io "nginx" not found
这是kubectl版本:
Client Version: version.Info{Major:"1", Minor:"19", GitVersion:"v1.19.2", GitCommit:"f5743093fd1c663cb0cbc89748f730662345d44d", GitTreeState:"clean", BuildDate:"2020-09-16T13:41:02Z", GoVersion:"go1.15", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"19", GitVersion:"v1.19.2", GitCommit:"f5743093fd1c663cb0cbc89748f730662345d44d", GitTreeState:"clean", BuildDate:"2020-09-16T13:32:58Z", GoVersion:"go1.15", Compiler:"gc", Platform:"linux/amd64"}
我做了很多搜索,但仍然找不到解决这个问题的方法。也已经尝试过多次重新安装,但始终不起作用。
我认为这可能是因为您希望在有限的命名空间中使用nginx入口控制器。请尝试将此补丁应用于您的ClusterRole
定义nginx-ingress-clusterrole
:
@@ -157,7 +160,7 @@ rules:
- list
- watch
- apiGroups:
- - "extensions"
+ - "networking.k8s.io"
resources:
- ingresses
verbs:
看看:集群角色nginx控制器。
对于我的设置,IngressClass
并没有像Zzorica回答的那样创建。具体来说,需要应用此配置。
另外,不要忘记添加
spec:
ingressClassName: nginx
也添加到您的Ingress
对象。
您还需要添加
kubectl apply -f common/ingress-class.yaml
有关IngressClass和1.18+中所做更改的更多信息,请访问https://kubernetes.io/docs/concepts/services-networking/ingress/