Ingress 实战

创建 Deployment

deploy-web.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: web
  labels:
    app: nginx
spec:
  replicas: 2
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:latest
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 80
          name: web

创建

修改 html 以区分(可选)

创建 Service

svc-ng.yaml

创建

创建 Ingress

ingress-web.yaml

命令行创建(可选)

访问

方式一:临时映射

直接将 nginx-ingress controller 对应的pod端口映射到本机

方式二:NodePort

svc-nodeport-ingress.yaml

修改本地hosts

访问

Last updated