如何使我的第一次进入在裸机NodeIP上工作?



我有pod:

apiVersion: apps/v1
kind: Deployment
metadata:
name: hello-app
namespace: dev
spec:
selector:
matchLabels:
app: hello
replicas: 3
template:
metadata:
labels:
app: hello
spec:
containers:
- name: hello
image: "gcr.io/google-samples/hello-app:2.0"

使服务:

---
apiVersion: v1
kind: Service
metadata:
name: hello-service
namespace: dev
labels:
app: hello
spec:
type: ClusterIP
selector:
app: hello
ports:
- port: 80
targetPort: 8080
protocol: TCP

检查:

---
apiVersion: v1
kind: Service
metadata:
name: hello-node-service
namespace: dev
spec:
type: NodePort
selector:
app: hello
ports:
- port: 80
targetPort: 8080

$ kubectl get SVC -n dev

NAME                 TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)        AGE
hello-node-service   NodePort    10.233.3.50     <none>        80:31263/TCP   9h
hello-service        ClusterIP   10.233.45.159   <none>        80/TCP         44h

$ curl -I http://cluster.local:31263

HTTP/1.1 200 OK
Date: Sat, 11 Sep 2021 07:31:28 GMT
Content-Length: 66
Content-Type: text/plain; charset=utf-8

我已经验证了服务正在工作。

使用NodeIP (https://kubernetes.github.io/ingress-nginx/deploy/):)安装ingress

kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.0.0/deploy/static/provider/baremetal/deploy.yaml

$ kubectl get pods -n ingress-nginx -l app.kubernetes。io/name = ingress-nginx——看

NAME                                       READY   STATUS      RESTARTS   AGE
ingress-nginx-admission-create-7gsft       0/1     Completed   0          10h
ingress-nginx-admission-patch-qj57b        0/1     Completed   1          10h
ingress-nginx-controller-8cf5559f8-mh6fr   1/1     Running     0          10h

$ kubectl get SVC -n入口-nginx

NAME                                 TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)                      AGE
ingress-nginx-controller             NodePort    10.233.52.118   <none>        80:30377/TCP,443:31682/TCP   10h
ingress-nginx-controller-admission   ClusterIP   10.233.51.175   <none>        443/TCP                      10h

检查:

$ curl -I http://cluster.local:30377/healthz

HTTP/1.1 200 OK
Date: Sat, 11 Sep 2021 07:39:04 GMT
Content-Type: text/html
Content-Length: 0
Connection: keep-alive

使入口:

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 -I http://cluster.local:30377/hello
HTTP/1.1 404 Not Found
Date: Sat, 11 Sep 2021 07:40:43 GMT
Content-Type: text/html
Content-Length: 146
Connection: keep-alive

它不工作。我花了几天时间,尝试将ExternalIP添加到入口控制器。

你能告诉我谁有设置入口的经验,我做错了什么?= (((

INFO about cluster:$ kubectl get ingress -n dev

NAME            CLASS    HOSTS           ADDRESS   PORTS   AGE
ingress-hello   <none>   cluster.local             80      10h

$ kubectl get nodes

NAME               STATUS   ROLES                  AGE   VERSION
kuber-ingress-01   Ready    worker                 10d   v1.21.3
kuber-master1      Ready    control-plane,master   10d   v1.21.3
kuber-master2      Ready    control-plane,master   10d   v1.21.3
kuber-master3      Ready    control-plane,master   10d   v1.21.3
kuber-node-01      Ready    worker                 10d   v1.21.3
kuber-node-02      Ready    worker                 10d   v1.21.3
kuber-node-03      Ready    worker                 10d   v1.21.3

库存:

kuber-master1 10.0.57.31
kuber-master2 10.0.57.32
kuber-master3 10.0.57.33
kuber-node-01 10.0.57.34
kuber-node-02 10.0.57.35
kuber-node-03 10.0.57.36
kuber-ingress-01 10.0.57.30
$ ping cluster.local
PING cluster.local (10.0.57.30) 56(84) bytes of data.
64 bytes from ingress.example.com (10.0.57.30): icmp_seq=1 ttl=62 time=0.603 ms

解决方案是在入口注释中添加以下内容。然后,入口控制器开始看到DNS地址。

annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/ssl-redirect: "false"
nginx.ingress.kubernetes.io/use-regex: "true"
nginx.ingress.kubernetes.io/rewrite-target: /$1

另外,为了方便,将path:/改为正则表达式:

- path: /v1(/|$)(.*)

相关内容

  • 没有找到相关文章

最新更新