您好,我刚刚开始尝试kubernetes,无法让我的入口资源和控制器正常工作,并将外部流量路由到我在集群中的服务。 我的环境详细信息 Windows的Docker桌面 kubernetes版本1.10.11(通过命令Kubectl版本获得) OS = windows10 64位
我已从以下链接获取了入口 https://kubernetes.github.io/ingress-nginx/deploy/
使用这两个命令
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/mandatory.yaml
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/provider/cloud-generic.yaml
然后我创建了一个入口资源,例如
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
kubernetes.io/ingress.class: nginx
name: sample-ingress1
spec:
rules:
- host: mysuperbot.com
http:
paths:
- path: /sampleingress
backend:
serviceName: tomcatappservice
servicePort: 8082
我的服务资源如下
---
apiVersion: v1
kind: Service
metadata:
name: tomcatappservice
labels:
app: tomcat-app
spec:
ports:
- port: 8082
protocol: TCP
targetPort: 8080
selector:
app: tomcat-app
type: NodePort
---
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: tomcat-app
labels:
app: tomcat-app
spec:
replicas: 5
selector:
matchLabels:
app: tomcat-app
template:
metadata:
labels:
app: tomcat-app
spec:
containers:
- image: tomcatapp:v1.0.0
name: tomcat-app
ports:
- containerPort: 8080
并且我的主机文件具有条目
mysuperbot.com localhost
但是在所有这些之后,当我尝试访问mysuperbot.com/sampleingress上的服务时,出现错误ERR_NAME_RESOLUTION_FAILED
,这使我相信我的入口控制器设置不正确,因此我可以通过命令
kubectl get pods -n ingress-nginx
输出如下
NAME READY STATUS RESTARTS AGE
nginx-ingress-controller-7d84dd6bdf-vnjx5 0/1 Pending 0 2h
这意味着我的入口Pod不在启动中。我需要如何在Windows的docker-desktop随附的本地kubernetes集群上测试入口的帮助
更新
运行命令后
kubectl -n ingress-nginx describe pod nginx-ingress-controller-7d84dd6bdf-vnjx5
Name: nginx-ingress-controller-7d84dd6bdf-vnjx5
Namespace: ingress-nginx
Node: <none>
Labels: app.kubernetes.io/name=ingress-nginx
app.kubernetes.io/part-of=ingress-nginx
pod-template-hash=3840882689
Annotations: prometheus.io/port=10254
prometheus.io/scrape=true
Status: Pending
IP:
Controlled By: ReplicaSet/nginx-ingress-controller-7d84dd6bdf
Containers:
nginx-ingress-controller:
Image: quay.io/kubernetes-ingress-controller/nginx-ingress-controller:0.26.1
Ports: 80/TCP, 443/TCP
Host Ports: 0/TCP, 0/TCP
Args:
/nginx-ingress-controller
--configmap=$(POD_NAMESPACE)/nginx-configuration
--tcp-services-configmap=$(POD_NAMESPACE)/tcp-services
--udp-services-configmap=$(POD_NAMESPACE)/udp-services
--publish-service=$(POD_NAMESPACE)/ingress-nginx
--annotations-prefix=nginx.ingress.kubernetes.io
Liveness: http-get http://:10254/healthz delay=10s timeout=10s period=10s #success=1 #failure=3
Readiness: http-get http://:10254/healthz delay=0s timeout=10s period=10s #success=1 #failure=3
Environment:
POD_NAME: nginx-ingress-controller-7d84dd6bdf-vnjx5 (v1:metadata.name)
POD_NAMESPACE: ingress-nginx (v1:metadata.namespace)
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from nginx-ingress-serviceaccount-token-8md24 (ro)
Conditions:
Type Status
PodScheduled False
Volumes:
nginx-ingress-serviceaccount-token-8md24:
Type: Secret (a volume populated by a Secret)
SecretName: nginx-ingress-serviceaccount-token-8md24
Optional: false
QoS Class: BestEffort
Node-Selectors: kubernetes.io/os=linux
Tolerations: node.kubernetes.io/not-ready:NoExecute for 300s
node.kubernetes.io/unreachable:NoExecute for 300s
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Warning FailedScheduling 14s (x583 over 3h) default-scheduler 0/1 nodes are available: 1 node(s) didn't match node selector.
答案 0 :(得分:1)
在入口控制器中,您具有节点选择器 kubernetes.io/os=linux 您必须编辑一些节点/您的入口配置以匹配此标签。
kubectl get nodes - - show-labels
kubectl label nodes <node-name> <label-key>=<label-value>
https://kubernetes.io/docs/tasks/configure-pod-container/assign-pods-nodes/