Kubernetes1.18.3 使用ingress
Kubernetes1.18.3 使用ingress1-下载配置文件包链接: github下载百度网盘2-找到deploy文件夹下7个yaml文件提取出来3-分别修改default-backend.yaml和with-rbac.yaml4-创建kubectl create -f namespace.yamlkubectl create -f default-backend.yamlkubectl
·
Kubernetes1.18.3 使用ingress
1-下载配置文件包(ingress-nginx-0.11.0)
链接: github下载
链接: 百度网盘 提取码: urpf
2-找到deploy文件夹下7个yaml文件提取出来
3-分别修改default-backend.yaml和with-rbac.yaml
4-创建
# 首先为需要搭建的node设置label
kubectl label nodes k8s-master1 custom/ingress-controller-ready=true
kubectl label nodes k8s-master2 custom/ingress-controller-ready=true
kubectl label nodes k8s-master3 custom/ingress-controller-ready=true
kubectl create -f namespace.yaml
kubectl create -f default-backend.yaml
kubectl create -f configmap.yaml
kubectl create -f tcp-services-configmap.yaml
kubectl create -f udp-services-configmap.yaml
kubectl create -f rbac.yaml
kubectl create -f with-rbac.yaml
# 查询修改配置的两个文件是否创建pod成功
kubectl get pod --namespace=ingress-nginx -o wide
错误提示: 如果遇到nginx-ingress-controller-xxx一直处于pending,删除with-rbac.yaml文件的nodeSelector部分
5-创建两个测试service
vim my-nginx.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-nginx
spec:
replicas: 2
selector:
matchLabels:
run: my-nginx
template:
metadata:
labels:
run: my-nginx
spec:
containers:
- name: my-nginx
image: 192.168.0.88:5000/nginx:1.7.9
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: my-nginx
labels:
run: my-nginx
spec:
type: NodePort
ports:
- port: 80
targetPort: 80
nodePort: 30011
selector:
run: my-nginx
vim my-apache.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-apache
spec:
replicas: 2
selector:
matchLabels:
run: my-apache
template:
metadata:
labels:
run: my-apache
spec:
containers:
- name: my-apache
image: 192.168.0.88:5000/httpd:2.4
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: my-apache
labels:
run: my-apache
spec:
type: NodePort
ports:
- port: 80
targetPort: 80
nodePort: 30002
selector:
run: my-apache
新建service与pod
kubectl create -f my-nginx.yaml
kubectl create -f my-apache.yaml
6-创建ingress(host为ip映射,下面会解释)
vim my-ingress.yaml
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: test-ingress
namespace: default
spec:
rules:
- host: test.apache.ingress
http:
paths:
- path: /
backend:
serviceName: my-apache
servicePort: 80
- host: test.nginx.ingress
http:
paths:
- path: /
backend:
serviceName: my-nginx
servicePort: 80
# 创建
kubectl create -f my-ingress.yaml
7-修改host文件
vim /etc/hosts
# 自定义域名,ip映射(node节点ip,随机选一个即可)
192.168.0.12 test.nginx.ingress
192.168.0.12 test.apache.ingress
浏览器访问结果
更多推荐
已为社区贡献2条内容
所有评论(0)