「K8s」- Traefik Installation

  CREATED BY JENKINSBOT

内容简介

本文将介绍如何安装Traefik控制器。

系统环境

系统环境: CentOS Linux release 7.5.1804 (Core)
软件版本: Kubernetes v1.14.0
  Docker version 19.03.2, build 6a30dfc
  Helm v3.0.0-beta.3
网络信息: k8s-master 172.31.253.28
  k8s-node01 172.31.253.29

安装服务

# 参照官方文档

按照官方文档「Traefik/Kubernetes Ingress Controller」中的说明即可部署成功。

# 使用helm安装

helm install traefik stable/traefik \
    --set dashboard.enabled=true,serviceType=NodePort,dashboard.domain=dashboard.traefik,rbac.enabled=true  \
    --namespace kube-system

验证

定义Deploymnent、Service及Ingress资源。

kind: Deployment
apiVersion: extensions/v1beta1
metadata:
  name: web
  namespace: default
  labels:
    run: web
spec:
  replicas: 1
  selector:
    matchLabels:
      run: web
  template:
    metadata:
      creationTimestamp: null
      labels:
        run: web
    spec:
      containers:
        - name: web
          image: 'httpd:alpine'
          ports:
            - containerPort: 80
              protocol: TCP
          imagePullPolicy: Always
      restartPolicy: Always
      dnsPolicy: ClusterFirst
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 25%
      maxSurge: 25%
  revisionHistoryLimit: 10
  progressDeadlineSeconds: 600
-----
kind: Service
apiVersion: v1
metadata:
  name: web
  namespace: default
  labels:
    run: web
spec:
  ports:
    - protocol: TCP
      port: 80
      targetPort: 80
  selector:
    run: web
  clusterIP: 10.108.28.108
  type: NodePort
  externalTrafficPolicy: Cluster
-----
kind: Ingress
apiVersion: extensions/v1beta1
metadata:
  name: web
  namespace: default
  annotations:
    kubernetes.io/ingress.class: traefik
spec:
  rules:
    - host: hello-world.info
      http:
        paths:
          - path: /
            backend:
              serviceName: web
              servicePort: 80

如果有必要则先绑定HOST条目,然后在浏览器中访问http://hello-world.info地址,如果返回It works!则表示正常。

参考文献

Traefik/Kubernetes Ingress Controller
Kubernetes Traefik Installation (helm)
GitHub/helm/charts/stable/traefik