首页 > 系统相关 >K8S之Ingress常用Nginx、Traefik示例

K8S之Ingress常用Nginx、Traefik示例

时间:2024-08-23 14:20:14浏览次数:9  
标签:Ingress name 示例 Traefik app ingress nginx traefik metadata

Nginx Ingress

  1. 创建Pod、Service,定义如下

nginx-ingress-demo.yaml

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: nginx-deploy
  namespace: default
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx-demo
      replease: canary
  template:
    metadata:
      name: my-nginx
      labels:
        app: nginx-demo
        release: canary
    spec:
      containers:
      - name: my-nginx
        image: nginx
        imagePullPolicy: IfNotPresent
        ports:
        - name: http
          containerPort: 80

---          

apiVersion: v1
kind: Service
metadata:
  name: nginx-svc
  namespace: default
spec:
  selector:
    app: nginx-demo
    release: canary
  ports:
  - name: http
    port: 80
    targetPort: 80    

kubectl apply -f nginx-ingress-demo.yaml

  1. 定义Ingress Nginx
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: ingress-nginx
  annotations:
    kubenetes.io/ingress.class: "nginx"
spec:
  rules:
  - host:
    host:
      paths:
      - path:
        backend:
          serverName: nginx-svc
          servicePort: 80    

Tracefik Ingress

  1. 配置Tracefik
kind: Deployment
apiVersion: extensions/v1beta1
metadata:
  name: traefik-ingress-controller
  namespace: ingress-traefik 
  labels:
    k8s-app: traefik-ingress-lb
spec:
  replicas: 1
  selector:
    matchLabels:
      k8s-app: traefik-ingress-lb
      name: traefik-ingress-lb
  template:
    metadata:
      labels:
        k8s-app: traefik-ingress-lb
        name: traefik-ingress-lb
    spec:
      serviceAccountName: traefik-ingress-controller
      terminationGracePeriodSeconds: 60
#      tolerations:
#      - operator: "Exists"
#      nodeSelector:
#        kubernetes.io/hostname: master
      containers:
      - image: traefik:v1.7.17
        name: traefik-ingress-lb
        volumeMounts:
        - name: ssl
          mountPath: "/ssl"
        - name: config
          mountPath: "/config"
        ports:
        - name: http
          containerPort: 80
        - name: https
          containerPort: 443
        - name: admin
          containerPort: 8080
        args:
        - --configfile=/config/traefik.toml
        - --api
        - --kubernetes
        - --logLevel=INFO
      volumes:
      - name: ssl
        secret:
          secretName: traefik-cert
      - name: config
        configMap:
          name: traefik-conf
  1. 定义service
kind: Service
apiVersion: v1
metadata:
  name: traefik-ingress-service
  namespace: ingress-traefik 
spec:
  selector:
    k8s-app: traefik-ingress-lb
  ports:
    - protocol: TCP
      port: 80
      name: web
      nodePort: 38000
    - protocol: TCP
      port: 8080
      nodePort: 38080
      name: admin
  type: NodePort
  1. 定义Ingress
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: nginx-ingress-demo
  annotations:
    kubernetes.io/ingress.class: "traefik"
    traefik.ingress.kubernetes.io/app-root: /app/
    traefik.ingress.kubernetes.io/rewrite-target: /$2
    traefik.ingress.kubernetes.io/configuration-snippet: |
      rewrite ^(/app)$ $1/ redirect;
      rewrite ^/static/(.*)$ /app/static/$1 redirect;
      rewrite ^/image/(.*)$ /app/image/$1 redirect;
spec:
  rules:
  - host:
    http:
      paths:
      - backend:
          serviceName: nginx-demo
          servicePort: 80
        path: /app(/|$)(.*)

标签:Ingress,name,示例,Traefik,app,ingress,nginx,traefik,metadata
From: https://www.cnblogs.com/codechange/p/17859612.html

相关文章

  • 实战:软件架构系列之【早期微服务架构Spring Cloud Netflix中的5大组件示例】
    概叙科普文:万字细说微服务及其框架Netflix,SpringCloud,SpringCloudAlibaba梳理_微服务netflixalibaba-CSDN博客科普文:微服务之技术选型SpringCloudAlibaba_微服务架构图阿里巴巴-CSDN博客SpringCloudNetflix是SpringCloud生态系统中最早期的一个子项目,它为Spr......
  • python socket编辑示例 UDP
    服务端:fromsocketimportsocket,AF_INET,SOCK_DGRAMrecv_socket=socket(AF_INET,SOCK_DGRAM)recv_socket.bind(('127.0.0.1',8888))whileTrue:data,addr=recv_socket.recvfrom(1024)#接收数据print('客户说:',data.decode('......
  • python socket编辑示例
    服务端代码:fromsocketimportsocket,AF_INET,SOCK_STREAM#1.创建socket对象AF_INET:用于internet之间的进程通信,SOCK_STREAM:表示TCP协议server_socket=socket(AF_INET,SOCK_STREAM)#2.绑定ip和端口号ip='127.0.0.1'port=8888server_socket.bind((ip,p......
  • 看了几十篇论文,实现了个专业算法,用threejs做了个三维人员定位系统示例(已开源)
    需求“threejs中能不能给定几组三维坐标(或者CAD绘制的三维多段线),给一个断面形状,直接生成三维管道?”例如原始CAD图如下:要求用threejs获取线的三维坐标数据自动生成的三维管道效果图如下: 分析如果直接对每条线用threejs中的THREE.TubeGeometry去绘制的话,会出现交岔口出......
  • tanstack react-form antd示例
    import{useForm}from"@tanstack/react-form";import{zodValidator}from"@tanstack/zod-form-adapter";import{z}from"zod";importtype{FieldApi}from"@tanstack/react-form";import{Button,Input,Radio......
  • ChatGPT协助论文写作各阶段指令示例
    学境思源,一键生成论文初稿:AcademicIdeas-学境思源AI论文写作在学术论文写作过程中,我们经常面临选题、文献综述、研究设计、数据分析、写作润色等多方面的挑战。人工智能技术的发展为这些挑战提供了新的解决方案。ChatGPT作为一款强大的语言模型,能够在论文写作的各个阶段提......
  • 体育数据API纳米奥运会数据API:高阶数据包接口文档API示例⑦
    纳米体育数据的数据接口通过JSON拉流方式获取200多个国家的体育赛事实时数据或历史数据的编程接口,无请求次数限制,可按需购买,接口稳定高效;覆盖项目包括足球、篮球、网球、电子竞技、奥运等专题、数据内容。纳米数据API2.0版本包含http协议以及websocket协议,主要通过http获取数......
  • Ansible Jinja2 使用及示例
    目录Jinja2Jinja2For循环Jinja2If条件Jinja多值合并Jinja2掌握了Jinja才是深入Ansible-playbook的开始Jinja2For循环变量的提取使用{{variable}}{%statementexecution%}括起来的内容为Jinja2命令执行语句{%foriteminall_items%}{{item}}{%endfor......
  • stencil示例
    stencil是一个webcomponents开发框架。pnpmcreatestencilmy.counter.tsx:import{Component,h,Prop,State}from"@stencil/core";@Component({ tag:"my-counter", styleUrl:"my-counter.css", shadow:true,})exportclassMyCou......
  • lwc示例
    lwc是一个webcomponents开发工具。pnpmcreatelwr选择SPA。项目生成后,一些运行时包并不在package.json中,需手动安装。package.json:{"name":"lwrdemo","version":"0.0.1","license":"MIT","private":true,......