zoukankan      html  css  js  c++  java
  • k8s安装traefik

    traefik是k3s(不道k3s是啥?赶紧搜下吧) 带的一个ingress-controller。因为当初k8s安装nginx-ingress和ingress-nginx两个东西时,费了好大的劲,想着或许traefik比那两个货好安装点吧。就想试下。

    1. 安装traefik

      

    apiVersion: v1
    kind: ServiceAccount
    metadata:
      name: traefik-ingress-controller
    
    ---
    kind: Deployment
    apiVersion: apps/v1
    metadata:
      name: traefik
      labels:
        app: traefik
    
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: traefik
      template:
        metadata:
          labels:
            app: traefik
        spec:
          serviceAccountName: traefik-ingress-controller
          containers:
            - name: traefik
              image: traefik:v2.4
              args:
                - --entrypoints.web.address=:80
                - --providers.kubernetesingress
              ports:
                - name: web
                  containerPort: 80
    
    ---
    apiVersion: v1
    kind: Service
    metadata:
      name: traefik
    spec:
    #  type: LoadBalancer      LoadBalance is only in the cloud env, kubeadm has no LoadBalance, so modify type to NodePort
      type: NodePort
      selector:
        app: traefik
      ports:
        - protocol: TCP
          port: 80
          name: web
          targetPort: 80

    2. rbac

    kind: ClusterRole
    apiVersion: rbac.authorization.k8s.io/v1
    metadata:
      name: traefik-ingress-controller
    rules:
      - apiGroups:
          - ""
        resources:
          - services
          - endpoints
          - secrets
        verbs:
          - get
          - list
          - watch
      - apiGroups:
          - extensions
          - networking.k8s.io
        resources:
          - ingresses
          - ingressclasses
        verbs:
          - get
          - list
          - watch
      - apiGroups:
          - extensions
        resources:
          - ingresses/status
        verbs:
          - update
    
    ---
    kind: ClusterRoleBinding
    apiVersion: rbac.authorization.k8s.io/v1
    metadata:
      name: traefik-ingress-controller
    roleRef:
      apiGroup: rbac.authorization.k8s.io
      kind: ClusterRole
      name: traefik-ingress-controller
    subjects:
      - kind: ServiceAccount
        name: traefik-ingress-controller
        namespace: default

    3. whoami服务

    kind: Deployment
    apiVersion: apps/v1
    metadata:
      name: whoami
      labels:
        app: traefiklabs
        name: whoami
    
    spec:
      replicas: 2
      selector:
        matchLabels:
          app: traefiklabs
          task: whoami
      template:
        metadata:
          labels:
            app: traefiklabs
            task: whoami
        spec:
          containers:
            - name: whoami
              image: traefik/whoami
              ports:
                - containerPort: 80
    
    ---
    apiVersion: v1
    kind: Service
    metadata:
      name: whoami
    
    spec:
      ports:
        - name: http
          port: 80
      selector:
        app: traefiklabs
        task: whoami

    4. whoami的ingress规则

    kind: Ingress
    apiVersion: networking.k8s.io/v1
    metadata:
      name: whoami-ingress
      annotations:
        traefik.ingress.kubernetes.io/router.entrypoints: web
    
    spec:
      rules:
      - host:
        http:
          paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: whoami
                port:
                  number: 80

    5. 访问

      因为traefik是NodePort类型的,所以集群的任一节点都可访问.

    # kubectl get svc --all-namespaces
    NAMESPACE              NAME                        TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)                      AGE
    ......

    default traefik NodePort 10.50.246.22 <none> 80:31768/TCP 14d

     31768就是对外的端口号

     访问地址就是: http://192.168.1.xx:31768

  • 相关阅读:
    Duilib 源码分析(二)消息处理
    Duilib 源码分析(一)示例推演
    2021 Duilib最新入门教程(七)Duilib处理消息
    2021 Duilib最新入门教程(六)Duilib界面设计
    2021 Duilib最新入门教程(五)Duilib调用静态库示例
    2021 Duilib最新入门教程(四)Duilib编译静态库
    源文件(cpp)、静态库(lib)、动态库(dll)
    2021 Duilib最新入门教程(三)Duilib调用动态库示例
    supernova-SN_TV MUF简介
    jieba+pyecharts 词云图应用
  • 原文地址:https://www.cnblogs.com/bear129/p/14738925.html
Copyright © 2011-2022 走看看