前言:不要盲目追新,不要盲目追新,不要盲目追新。这几天ingress安装不下就是因为新版本我下载不下来最新的镜像,并且这类新版本的安装内容也找不到借鉴的。
ingress-nginx版本
- 查看自己的k8s安装对应的ingress:https://github.com/kubernetes/ingress-nginx
- 我安装的是最新版的
安装方法
下载yaml文件
- wget https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.1.0/deploy/static/provider/baremetal/deploy.yaml
- yaml默认是deployment部署方式
# 下载yaml wget https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.1.0/deploy/static/provider/baremetal/deploy.yaml # 修改文件名 mv deploy.yaml ingress-nginx-v1.1.0.yaml # 修改镜像 [root@k8s-master-1 tmp]# grep "image: *" deploy.yaml image: k8s.gcr.io/ingress-nginx/controller:v1.0.5@sha256:55a1fcda5b7657c372515fe402c3e39ad93aa59f6e4378e82acd99912fe6028d image: k8s.gcr.io/ingress-nginx/kube-webhook-certgen:v1.1.1@sha256:64d8c73dca984af206adf9d6d7e46aa550362b1d7a01f3a0a91b20cc67868660 image: k8s.gcr.io/ingress-nginx/kube-webhook-certgen:v1.1.1@sha256:64d8c73dca984af206adf9d6d7e46aa550362b1d7a01f3a0a91b20cc67868660 # 修改为下面的 [root@k8s-master-1 ~]# grep "image: *" ingress-nginx-v1.1.0.yaml image: liangjw/ingress-nginx-controller:v1.1.0 image: liangjw/kube-webhook-certgen:v1.1.1 image: liangjw/kube-webhook-certgen:v1.1.1 [root@k8s-master-1 tmp]# kubectl apply -f ingress-nginx-v1.1.0.yaml # 下面表示安装成功 [root@k8s-master-1 tmp]# kubectl get pods -n ingress-nginx -o wide --watch NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES ingress-nginx-admission-create--1-hkkcj 0/1 Completed 0 15m 10.244.3.46 k8s-node-11.host.com <none> <none> ingress-nginx-admission-patch--1-kj6bc 0/1 Completed 1 15m 10.244.3.45 k8s-node-11.host.com <none> <none> ingress-nginx-controller-6fb6b646f-jgttm 1/1 Running 0 15m 10.244.3.47 k8s-node-11.host.com <none> <none>
- 这里我要提一下,由于某些原因下载不了ingress默认镜像,所以我去dockerhub上找了,还真找到了,感谢这位大兄弟
测试ingress是否有用
- 这里ingress-nginx是NodePort模式,所以直接占用node2个端口,分别是80:32715/TCP,443:30691/TCP,也就是访问node:32715就能转发到ingress-nginx 80端口,访问node:30691就能转发到ingress-nginx 443端口
[root@k8s-node-11 data]# k get pods,svc -n ingress-nginx NAME READY STATUS RESTARTS AGE pod/ingress-nginx-admission-create--1-hkkcj 0/1 Completed 0 29h pod/ingress-nginx-admission-patch--1-kj6bc 0/1 Completed 1 29h pod/ingress-nginx-controller-6fb6b646f-jgttm 1/1 Running 0 29h NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE service/ingress-nginx-controller NodePort 172.17.11.31 <none> 80:32715/TCP,443:30691/TCP 29h service/ingress-nginx-controller-admission ClusterIP 172.17.29.61 <none> 443/TCP 29h
- 部署一个hello world并使用ingress-nginx
apiVersion: apps/v1 kind: Deployment metadata: name: hello-server spec: replicas: 2 selector: matchLabels: app: hello-server template: metadata: labels: app: hello-server spec: containers: - name: hello-server image: registry.cn-hangzhou.aliyuncs.com/lfy_k8s_images/hello-server ports: - containerPort: 9000 --- apiVersion: v1 kind: Service metadata: labels: app: hello-server name: hello-server spec: selector: app: hello-server ports: - port: 8000 protocol: TCP targetPort: 9000
- 部署
[root@k8s-master-1 test]# k apply -f hello-world-dp.yaml deployment.apps/hello-server unchanged service/hello-server unchanged # 查看是否跑起来了 [root@k8s-master-1 test]# k get pods,svc |grep hello pod/hello-server-6cbb679d85-bfrw2 1/1 Running 0 22h pod/hello-server-6cbb679d85-j7rnv 1/1 Running 0 22h service/hello-server ClusterIP 172.17.222.237 <none> 8000/TCP 22h # 直接访问ip,输出Hello World!表示没有问题 [root@k8s-master-1 test]# curl 172.17.222.237:8000 Hello World! #
- 部署ingress配置
apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: hello-world-ingress spec: ingressClassName: nginx rules: - host: "hello.home.com" http: paths: - pathType: Prefix path: "/hello" backend: service: name: hello-server port: number: 8000
- 检查ingres
[root@k8s-master-1 test]# vim hello-world-ingress-rule1.yaml [root@k8s-master-1 test]# k apply -f hello-world-ingress-rule1.yaml ingress.networking.k8s.io/hello-world-ingress created [root@k8s-master-1 test]# k get ingress |grep hello hello-world-ingress nginx hello.home.com 10.4.7.11 80 41s
- 配置本地hosts或者路由器的hosts,并访问域名
- 注意10.4.7.12是你的node节点ip,master节点ip也可以
原创文章,作者:站长,如若转载,请注明出处:https://wsppx.cn/2432/%e7%bd%91%e7%ab%99%e9%83%a8%e7%bd%b2/