以前,我尝试使用 NodeIP 使其工作入口。 如何让 My First ingress 在裸机 NodeIP 上运行? 它也不起作用,也许问题和现在一样,我没有正确配置它。
我放弃了这个选项并尝试了 MetalllLB + Ingress
!我在这两种情况下所做的:!我仅在我的工作机器上通过 /etc/hosts 安装了 DNS。
10.0.57.28 cluster.local test.local ingress.example.com dashboard.cluster.local test.cluster.local test.com
带 Helm 的安装 metallb:
helm repo add metallb https://metallb.github.io/metallb
helm install metallb metallb/metallb -f values.yaml
值.yaml
configInline:
address-pools:
- name: default
protocol: layer2
addresses:
- 10.0.57.28-10.0.57.29
使用 Helm¶ 安装入口控制器:
helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
helm repo update
helm install ingress-nginx ingress-nginx/ingress-nginx
获取 svc -A
NAMESPACE NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
default ingress-nginx-controller LoadBalancer 10.233.3.75 10.0.57.28 80:30963/TCP,443:32376/TCP 19s
提供服务
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ingress-hello
namespace: dev
spec:
rules:
- host: "test.com"
http:
paths:
- backend:
service:
name: hello-service
port:
number: 80
path: /
pathType: Prefix
进入:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ingress-hello
namespace: dev
spec:
rules:
- host: cluster.local
http:
paths:
- backend:
service:
name: hello-service
port:
number: 80
path: "/hello"
pathType: Prefix
curl -D- http://cluster.local/hello
HTTP/1.1 404 Not Found
Date: Sat, 11 Sep 2021 17:26:27 GMT
Content-Type: text/html
Content-Length: 146
Connection: keep-alive
<html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx</center>
</body>
</html>
kubectl 获取 svc -A
NAMESPACE NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
default ingress-nginx-controller LoadBalancer 10.233.3.75 10.0.57.28 80:30963/TCP,443:32376/TCP 25m
default ingress-nginx-controller-admission ClusterIP 10.233.13.161 <none> 443/TCP 25m
default ireg ClusterIP 10.233.34.105 <none> 8080/TCP 8d
default kubernetes ClusterIP 10.233.0.1 <none> 443/TCP 10d
dev hello-node-service NodePort 10.233.3.50 <none> 80:31263/TCP 19h
dev hello-service ClusterIP 10.233.45.159 <none> 80/TCP 2d6h
kube-system coredns ClusterIP 10.233.0.3 <none> 53/UDP,53/TCP,9153/TCP 10d
kube-system metrics-server ClusterIP 10.233.27.232 <none> 443/TCP 34h
kubernetes-dashboard dashboard-metrics-scraper ClusterIP 10.233.29.129 <none> 8000/TCP 10d
kubernetes-dashboard kubernetes-dashboard ClusterIP 10.233.36.25 <none> 443/TCP 10d
检查“你好”吊舱
service_hello_Node.yml
---
apiVersion: v1
kind: Service
metadata:
name: hello-node-service
namespace: dev
spec:
type: NodePort
selector:
app: hello
ports:
- port: 80
targetPort: 8080
卷曲-I 10.0.57.35:31263
HTTP/1.1 200 OK
Date: Sat, 11 Sep 2021 17:28:46 GMT
Content-Length: 66
Content-Type: text/plain; charset=utf-8
kubectl 描述 pod ingress-nginx-controller-fd7bb8d66-mvc9d
请帮助我为什么入口不起作用。也许我需要以特定方式自定义 DNS?
Service 和 Ingress 在同一个命名空间中。Ingress Controller 在不同的地方。
我查看入口控制器日志 - 什么都没有,这正常吗?
kubectl 描述 pod ingress-nginx-controller-fd7bb8d66-mvc9d
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 19m default-scheduler Successfully assigned default/ingress-nginx-controller-fd7bb8d66-mvc9d to kuber-node-01
Normal Pulled 19m kubelet Container image "k8s.gcr.io/ingress-nginx/controller:v1.0.0@sha256:0851b34f69f69352bf168e6ccf30e1e20714a264ab1ecd1933e4d8c0fc3215c6" already present on machine
Normal Created 19m kubelet Created container controller
Normal Started 19m kubelet Started container controller
Normal RELOAD 19m nginx-ingress-controller NGINX reload triggered due to a change in configuration
kubectl 获取 pod -A
NAMESPACE NAME READY STATUS RESTARTS AGE
default ingress-nginx-controller-fd7bb8d66-mvc9d 1/1 Running 0 22m
default ireg-685d4b86fb-rwjpj 1/1 Running 1 27h
default metallb-controller-748756655f-ss6w7 1/1 Running 0 93m
default metallb-speaker-2tf86 1/1 Running 0 93m
default metallb-speaker-6xht6 1/1 Running 0 93m
default metallb-speaker-9wjrm 1/1 Running 0 93m
default metallb-speaker-b28fv 1/1 Running 0 93m
default metallb-speaker-jdv4z 1/1 Running 0 93m
default metallb-speaker-svwjz 1/1 Running 0 93m
default metallb-speaker-xd22w 1/1 Running 0 93m
dev hello-app-78f957775f-7d7bw 1/1 Running 1 27h
dev hello-app-78f957775f-hj9gb 1/1 Running 1 9h
dev hello-app-78f957775f-wr7b2 1/1 Running 1 9h
kube-system calico-kube-controllers-5b4d7b4594-5qfjc 1/1 Running 1 27h
kube-system calico-node-7mcqc 1/1 Running 1 10d
kube-system calico-node-9trpd 1/1 Running 1 10d
kube-system calico-node-fl55n 1/1 Running 1 10d
kube-system calico-node-g9zxw 1/1 Running 1 10d
kube-system calico-node-j8fqp 1/1 Running 0 10d
kube-system calico-node-jhz72 1/1 Running 0 10d
kube-system calico-node-rrcm4 1/1 Running 0 10d
kube-system coredns-8474476ff8-552fq 1/1 Running 0 27h
kube-system coredns-8474476ff8-h45sp 1/1 Running 0 27h
kube-system dns-autoscaler-7df78bfcfb-xzkg9 1/1 Running 0 27h
kube-system kube-apiserver-kuber-master1 1/1 Running 0 10d
kube-system kube-apiserver-kuber-master2 1/1 Running 0 34h
kube-system kube-apiserver-kuber-master3 1/1 Running 0 34h
kube-system kube-controller-manager-kuber-master1 1/1 Running 0 10d
kube-system kube-controller-manager-kuber-master2 1/1 Running 1 10d
kube-system kube-controller-manager-kuber-master3 1/1 Running 1 10d
kube-system kube-proxy-52566 1/1 Running 1 27h
kube-system kube-proxy-6bwrt 1/1 Running 0 27h
kube-system kube-proxy-fxkv6 1/1 Running 1 27h
kube-system kube-proxy-kmjnf 1/1 Running 1 27h
kube-system kube-proxy-pnbss 1/1 Running 0 27h
kube-system kube-proxy-tf9ck 1/1 Running 1 27h
kube-system kube-proxy-tt4gv 1/1 Running 0 27h
kube-system kube-scheduler-kuber-master1 1/1 Running 0 10d
kube-system kube-scheduler-kuber-master2 1/1 Running 0 10d
kube-system kube-scheduler-kuber-master3 1/1 Running 1 10d
kube-system metrics-server-ddf5ffb86-27q7x 2/2 Running 0 27h
kube-system nginx-proxy-kuber-ingress-01 1/1 Running 1 10d
kube-system nginx-proxy-kuber-node-01 1/1 Running 1 10d
kube-system nginx-proxy-kuber-node-02 1/1 Running 1 10d
kube-system nginx-proxy-kuber-node-03 1/1 Running 1 10d
kube-system nodelocaldns-2clp8 1/1 Running 0 10d
kube-system nodelocaldns-b4552 1/1 Running 1 10d
kube-system nodelocaldns-hkffk 1/1 Running 1 10d
kube-system nodelocaldns-jflnt 1/1 Running 0 10d
kube-system nodelocaldns-k7cn7 1/1 Running 1 10d
kube-system nodelocaldns-ksd4t 1/1 Running 1 10d
kube-system nodelocaldns-xm544 1/1 Running 0 10d
kubernetes-dashboard dashboard-metrics-scraper-856586f554-thz5d 1/1 Running 1 27h
kubernetes-dashboard kubernetes-dashboard-67484c44f6-mgqgr 1/1 Running 0 9h