1. 环境
REPOSITORY TAG
nginx 1.23.1
debian latest
mysql 5.7.38
registry.k8s.io/ingress-nginx/controller v1.3.0
wordpress 6.0.0-php7.4-apache
hubproxy.docker.internal:5000/docker/desktop-kubernetes kubernetes-v1.24.2-cni-v1.1.1-critools-v1.24.2-cri-dockerd-v0.2.1-1-debian
k8s.gcr.io/kube-apiserver v1.24.2
k8s.gcr.io/kube-scheduler v1.24.2
k8s.gcr.io/kube-controller-manager v1.24.2
k8s.gcr.io/kube-proxy v1.24.2
kubernetesui/dashboard v2.6.0
kubernetesui/metrics-scraper v1.0.8
k8s.gcr.io/etcd 3.5.3-0
k8s.gcr.io/pause 3.7
registry.k8s.io/ingress-nginx/kube-webhook-certgen v1.1.1
k8s.gcr.io/coredns/coredns v1.8.6
docker/desktop-vpnkit-controller v2.0
docker/desktop-storage-provisioner v2.0
2. 部署 ingress-nginx
# 1、启动 ExpressVPN
# ingress-nginx 部署的时候会拉取以下2个镜像文件
# registry.k8s.io/ingress-nginx/kube-webhook-certgen:v1.1.1
# registry.k8s.io/ingress-nginx/controller:v1.3.0
# 2、执行以下命令:
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.3.0/deploy/static/provider/cloud/deploy.yaml
# 或者
kubectl apply -f https://github.com/kubernetes/ingress-nginx/blob/controller-v1.3.0/deploy/static/provider/cloud/deploy.yaml
3. 测试:
# kubectl apply -f nginx-ingress.yaml
# kubectl delete -f nginx-ingress.yaml
# 在 hosts 文件中配置:
# 127.0.0.1 nginx.arno
#
# 注意:以下 ingressClassName: nginx 依赖于上面 ingress-nginx 中的 IngressClass 资源
# IngressClass 用于处理规则
# Ingress 用于插件服务于 Service 的规则
---
kind: Deployment
apiVersion: apps/v1
metadata:
namespace: arno
name: nginx
spec:
selector:
matchLabels:
app: nginx
replicas: 1
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.23.1
ports:
- containerPort: 80
protocol: TCP
---
kind: Service
apiVersion: v1
metadata:
namespace: arno
name: nginx
labels:
app: nginx
spec:
type: ClusterIP
selector:
app: nginx
ports:
- protocol: TCP
port: 80
targetPort: 80
---
kind: Ingress
apiVersion: networking.k8s.io/v1
metadata:
namespace: arno
name: nginx
spec:
ingressClassName: nginx
rules:
- host: nginx.arno
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: nginx
port:
number: 80
4. 参考: