首页 > 其他分享 >部署 Traefik 实现 dashboard 与 原生Ingress使用 CRD IngressRoute使用

部署 Traefik 实现 dashboard 与 原生Ingress使用 CRD IngressRoute使用

时间:2024-10-27 09:32:59浏览次数:8  
标签:IngressRoute Ingress name Traefik namespace kind nginx traefik metadata

部署Traefik

00-namespace.yml

apiVersion: v1
kind: Namespace
metadata:
  name: test-traefik

00-role.yml

kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: traefik-role
  namespace: test-traefik
rules:
  - apiGroups:
      - ""
    resources:
      - services
      - secrets
      - nodes
    verbs:
      - get
      - list
      - watch
  - apiGroups:
      - discovery.k8s.io
    resources:
      - endpointslices
    verbs:
      - list
      - watch
  - apiGroups:
      - extensions
      - networking.k8s.io
    resources:
      - ingresses
      - ingressclasses
    verbs:
      - get
      - list
      - watch
  - apiGroups:
      - extensions
      - networking.k8s.io
    resources:
      - ingresses/status
    verbs:
      - update
  - apiGroups:
      - traefik.io
    resources:
      - middlewares
      - middlewaretcps
      - ingressroutes
      - traefikservices
      - ingressroutetcps
      - ingressrouteudps
      - tlsoptions
      - tlsstores
      - serverstransports
      - serverstransporttcps
    verbs:
      - get
      - list
      - watch

00-account.yml

apiVersion: v1
kind: ServiceAccount
metadata:
  name: traefik-account
  namespace: test-traefik

01-role-binding.yml

kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: traefik-role-binding
  namespace: test-traefik
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: traefik-role
subjects:
  - kind: ServiceAccount
    name: traefik-account
    namespace: test-traefik

02-traefik.yml

kind: Deployment
apiVersion: apps/v1
metadata:
  name: traefik-deployment
  namespace: test-traefik
  labels:
    app: traefik

spec:
  replicas: 1
  selector:
    matchLabels:
      app: traefik
  template:
    metadata:
      labels:
        app: traefik
    spec:
      serviceAccountName: traefik-account
      containers:
        - name: traefik
          image: traefik:v3.1
          args:
            - --api.insecure
            - --providers.kubernetesingress
          ports:
            - name: web
              containerPort: 80
            - name: dashboard
              containerPort: 8080

02-traefik-services.yml

把 LoadBalancer 改成 NodePort

apiVersion: v1
kind: Service
metadata:
  name: traefik-dashboard-service
  namespace: test-traefik
spec:
  type: NodePort
  ports:
    - port: 8080
      targetPort: dashboard
  selector:
    app: traefik
---
apiVersion: v1
kind: Service
metadata:
  name: traefik-web-service
  namespace: test-traefik
spec:
  type: NodePort
  ports:
    - targetPort: web
      port: 80
  selector:
    app: traefik
kubectl apply -f 00-namespace.yml \
			  -f 00-role.yml \
              -f 00-account.yml \
              -f 01-role-binding.yml \
              -f 02-traefik.yml \
              -f 02-traefik-services.yml

kubectl get all -n test-traefik

访问Traefik Dashboard:http://127.0.0.1:32193/dashboard

Ingress示例

00-nginx-deployment.yaml

kind: Deployment
apiVersion: apps/v1
metadata:
  name: nginx
  namespace: test-traefik
  labels:
    app: nginx

spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
        - name: nginx
          image: swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/nginx:1.27.1
          ports:
            - name: web
              containerPort: 80

01-nginx-services.yaml

apiVersion: v1
kind: Service
metadata:
  name: nginx
  namespace: test-traefik
spec:
  ports:
    - name: web
      port: 80
      targetPort: web
  selector:
    app: nginx

02-nginx-ingress.yaml

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: nginx-ingress
  namespace: test-traefik
spec:
  rules:
  - http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: nginx
            port:
              name: web
kubectl apply -f 00-nginx-deployment.yaml \
			  -f 01-nginx-services.yaml    \
			  -f 02-nginx-ingress.yaml

访问http://127.0.0.1:32560/

ingressRoute示例

注意这里的kind为IngressRoute

00-nginx-ingressroute.yaml

apiVersion: traefik.io/v1alpha1
kind: IngressRoute
metadata:
  name: nginxIngressRoute
  namespace: test-traefik
spec:
  entryPoints:
    - web
  routes:
    - match: Host(`ingressRoute.example.com`)
      kind: Rule
      services:
        - name: nginx
          port: 80
kubectl apply -f 00-nginx-ingressroute.yaml

访问http://ingressroute.example.com:32560/

ingressRoute.example.com需要配置/etc/hosts文件进行ip与命名的映射,如果没有DNS服务。

参考:

https://blog.csdn.net/networken/article/details/85953346
https://blog.csdn.net/networken/article/details/85953346
https://doc.traefik.io/traefik/getting-started/quick-start-with-kubernetes/

标签:IngressRoute,Ingress,name,Traefik,namespace,kind,nginx,traefik,metadata
From: https://www.cnblogs.com/happyhuangjinjin/p/18507881

相关文章

  • 详解 helm 部署 traefik
    安装helm下载地址https://github.com/helm/helm/releases安装wgethttps://get.helm.sh/helm-v3.16.2-linux-amd64.tar.gztar-zxvfhelm-v3.16.2-linux-amd64.tar.gzcdlinux-amd64/chmod755helmmvhelm/usr/local/bin/helmversion添加traefik的helm源helmrep......
  • 详解 helm 部署 ingress-nginx
    使用Helm安装参考文档:https://kubernetes.github.io/ingress-nginx/deploy/添加ingress-nginx官方helm仓库helmrepoaddingress-nginxhttps://kubernetes.github.io/ingress-nginxhelmrepoupdate下载Chart包#查找所有的版本helmsearchrepoingress-nginx/ingress-n......
  • 在K8S中,有几种Controller控制器并说一下其工作原理及ingress-controller的工作机制。
    在Kubernetes(K8s)中,Controller控制器是核心组件,它们负责监控集群状态,并确保系统的期望状态与实际状态一致。以下是几种常见的Controller控制器及其工作原理,以及ingress-controller的工作机制的详细介绍:1.常见的Controller控制器及其工作原理ReplicationController作用:确保指......
  • 在K8S中,ingress 有何作用?
    在Kubernetes(简称K8S)中,Ingress是一种API资源对象,用于管理从集群外部到集群内部服务的HTTP和HTTPS连接。它主要用来定义网络路由规则,允许外部用户通过特定的路径访问部署在集群内的应用服务。Ingress控制器则是实际实现这些规则的组件,通常运行在一个或多个Pod中,并监听......
  • 一文读懂Ingress-Nginx以及实践攻略
    一文读懂Ingress-Nginx以及实践攻略目录1概念1.1什么是Ingress?1.1.1主要功能:1.2Ingress的组件1.3什么是ingress-nginx1.4ingress-nginx优点和限制1.5版本兼容性矩阵2实践:Ingressnginx部署2.1使用helm部署ingress-nginx2.1.1安装和配置Helm2.1.2配置和......
  • ingress-https
     apiVersion:networking.k8s.io/v1kind:Ingressmetadata:annotations:nginx.ingress.kubernetes.io/backend-protocol:HTTPSnginx.ingress.kubernetes.io/force-ssl-redirect:"true"creationTimestamp:"2024-09-26T07:34:58Z"......
  • Kubernetes中Ingress的原理和配置
    Ingress的概念和作用Ingress是Kubernetes集群中的一个对象,用于将外部流量路由到集群内部的服务。它充当了进入Kubernetes集群的API网关,负责接收外部请求,并将其转发到正确的目标服务上。Ingress通常通过HTTP和HTTPS提供对服务的访问,并支持基于主机名、路径以及其他HTTP请求属性......
  • k8s Ingress和 Ingress Controller
    一、Ingress和IngressController概述关于service四层代理介绍链接点我跳转1.1Ingressingress是k8s中的资源,主要是管理ingress-controller这个代理的配置文件。Ingress是对集群中服务的外部访问进行管理的API对象,典型的访问方式是HTTP,Ingress可以提供负载均衡、SSL终结和基......
  • k8s 中的 Ingress 简介【k8s 系列之三】
    〇、前言前边已经介绍了k8s中的相关概念和Service,本文继续看下什么是Ingress。Ingress的重要性不言而喻,它不仅统一了集群对外访问的入口,还提供了高级路由、七层负载均衡、SSL终止等关键功能,同时支持动态配置更新、灰度发布等高级特性。下文将进行详细介绍。一、关于Ingr......
  • Kubernetes Ingress
    目录一、为什么需要Ingress二、什么是Ingress,IngressController三、Ingress的工作原理四、Ingress配置资源模版五、实例1、搭建Ingress环境1.1、Ingress-Nginx官网地址1.2、master节点下载deploy.yaml1.3、所有节点提前pull必须的镜像1.4、修改并应用deploy.yaml文件......