k3d | ingress方式访问nginx的service

系统与环境

vmware ubuntu18
linux
docker --> 我写的教程
k3d+kubectl --> 我写的教程

配置步骤

1.创建cluster,-p参数制定将host的8081端口映射到serverlb容器上的80端口,serverlb再代理到所有的server节点的80端口上

k3d cluster create  -p "8081:80@loadbalancer" --agents 2

2.部署deployment

kubectl apply -f nginx.yaml

nginx.yaml 文件内容如下图

apiVersion: apps/v1
kind: Deployment
metadata: 
  name: nginx
  labels:
    app: nginx

spec: 
  replicas: 1
  selector: 
    matchLabels: 
      app: nginx
  template: 
    metadata: 
      labels: 
        app: nginx
    spec: 
      containers: 
      - name: nginx
        image: nginx
        ports:
          - containerPort: 80

3.部署service

kubectl apply -f nginx.yaml

nginx.yaml文件如下

apiVersion: v1
kind: Service
metadata:
  name: nginx
spec:
  selector: 
    app: nginx
  ports: 
    - protocol: TCP
      port: 80
      targetPort: 80

4.部署ingress

kubectl apply -f nginx.yaml

nginx.yaml内容如下

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: nginx-ingress
  annotations:
    ingress.kubernetes.io/ssl-redirect: "false"
spec:
  rules:
  - http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: nginx
            port:
              number: 80
  1. 访问 hostport:8081


  2. 检查
    通过describe ing/svc等指令可以看到整体是否流通
    比如describe svc,后可以看到

Endpoints: 10.****

10.**** 如果和pod ip一致,则说明配置成功


你可能感兴趣的:(k3d | ingress方式访问nginx的service)