k8s ingress
2023-09-27 15:59 qgbo 阅读(32) 评论(2) 编辑 收藏 举报k8s 环境搭建完毕后
1. kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.8.2/deploy/static/provider/cloud/deploy.yaml 也可以copy 这个文件下来,执行
2.
kubectl create deployment demo --image=httpd --port=80 kubectl expose deployment demo kubectl create ingress demo-localhost --class=nginx --rule="demo.localdev.me/*=demo:80"
3. kubectl edit ingress demo-localhost 修改规则:
4. kubectl get svc -A 找到ingress-nginx-controller 这个service,
ingress-nginx ingress-nginx-controller LoadBalancer 10.101.36.242 <pending> 80:31594/TCP,443:31167/TCP 4h54m
这个端口31594 可以访问,curl localhost:31594
也可以
kubectl port-forward --namespace=ingress-nginx service/ingress-nginx-controller 8080:80 curl localhost:8080
5. install dashboard: https://kubernetes.io/docs/tasks/access-application-cluster/web-ui-dashboard/
6. 修改 端口范围:默认是 30000-32767, 修改 sudo vi /etc/kubernetes/manifests/kube-apiserver.yaml ,添加一行:- --service-node-port-range=8080-8089
如果不起效, 将第一步删掉: kubectl delete-f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.8.2/deploy/static/provider/cloud/deploy.yaml ,重新执行
这样端口是随机的,找到第一步的文件,找到这个service, ingress-nginx-controller , 改到想要的端口,就可以了。注意去掉
spec: externalTrafficPolicy: Local ipFamilies: - IPv4 ipFamilyPolicy: SingleStack
这和其他的service 一样,也可以设置为 NodePort
7. 其他:
最新: https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/deploy/static/provider/cloud/deploy.yaml 这个文件下来, 对 ingress-nginx-controller这个service 进行如下修改: a. 删除 externalTrafficPolicy: Local 这句。 b. 增加 externalIPs: - 10.48.86.141 (某个主机,如下最后2行) apiVersion: v1 kind: Service metadata: labels: app.kubernetes.io/component: controller app.kubernetes.io/instance: ingress-nginx app.kubernetes.io/name: ingress-nginx app.kubernetes.io/part-of: ingress-nginx app.kubernetes.io/version: 1.8.2 name: ingress-nginx-controller namespace: ingress-nginx spec: externalTrafficPolicy: Local ipFamilies: - IPv4 ipFamilyPolicy: SingleStack ports: - appProtocol: http name: http port: 80 protocol: TCP targetPort: http - appProtocol: https name: https port: 443 protocol: TCP targetPort: https selector: app.kubernetes.io/component: controller app.kubernetes.io/instance: ingress-nginx app.kubernetes.io/name: ingress-nginx type: LoadBalancer externalIPs: - 10.48.86.141
然后 apply, 即可访问 {host} 的8080