Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to deploy Traefik Ingress in Kubernetes

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article is about how to deploy Traefik Ingress in Kubernetes. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

One: preface

1. So far, there are three ways for Kubernetes to expose services, which are LoadBlancer Service, NodePort Service, and Ingress. The official website defines Ingress as managing the collection of rules between external services and services within the cluster. The popular point is that it defines rules to allow requests to enter the cluster to be forwarded to the corresponding services in the cluster, never realizing service leakage. Ingress can configure Service in the cluster as URL that can be accessed by external network, load balance traffic, terminate SSL, provide virtual hosts based on domain name access, and so on.

LoadBlancer Service:LoadBlancer Service is a component of Kubernetes combined with cloud platform, such as foreign GCE, AWS, domestic Aliyun, and so on. Using it to apply to the underlying cloud platform to create a load balancer is limited, and it is more convenient for clusters using cloud platform.

NodePort Service: NodePort Service realizes service leakage by exposing ports on nodes, and then mapping ports to a specific service, which is more intuitive and convenient, but for clusters, with the continuous increase of Service, more and more ports are needed, port conflicts are easy to occur, and it is not easy to manage. Of course, for small-scale cluster services, it is still quite good.

Ingress: Ingress uses open source reverse proxy load balancers to implement exposure services, such as Nginx, Apache, Haproxy, etc.

2.traefik is a front-end load balancer, which has good support for micro-service architecture, especially for orchestration tools such as kubernetes. Compared with nginx, traefik can automatically perceive back-end container changes, thus realizing automatic service discovery.

Two: yaml file

You can download the required yaml files through https://github.com/containous/traefik/tree/master/examples/k8s; we used the following files:

Traefik-rbac.yaml

Click (here) to collapse or open

-

Kind: ClusterRole

ApiVersion: rbac.authorization.k8s.io/v1beta1

Metadata:

Name: traefik-ingress-controller

Rules:

-apiGroups:

-"

Resources:

-services

-endpoints

-secrets

Verbs:

-get

-list

-watch

-apiGroups:

-extensions

Resources:

-ingresses

Verbs:

-get

-list

-watch

-

Kind: ClusterRoleBinding

ApiVersion: rbac.authorization.k8s.io/v1beta1

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: kube-system

Traefik-ds.yaml

Click (here) to collapse or open

-

ApiVersion: v1

Kind: ServiceAccount

Metadata:

Name: traefik-ingress-controller

Namespace: kube-system

-

Kind: DaemonSet

ApiVersion: extensions/v1beta1

Metadata:

Name: traefik-ingress-controller

Namespace: kube-system

Labels:

K8s-app: traefik-ingress-lb

Spec:

Template:

Metadata:

Labels:

K8s-app: traefik-ingress-lb

Name: traefik-ingress-lb

Spec:

ServiceAccountName: traefik-ingress-controller

TerminationGracePeriodSeconds: 60

HostNetwork: true

Containers:

-image: traefik

Name: traefik-ingress-lb

Ports:

-name: http

ContainerPort: 80

HostPort: 80

-name: admin

ContainerPort: 8080

SecurityContext:

Capabilities:

Drop:

-ALL

Add:

-NET_BIND_SERVICE

Args:

-api

-kubernetes

-logLevel=INFO

-

Kind: Service

ApiVersion: v1

Metadata:

Name: traefik-ingress-service

Namespace: kube-system

Spec:

Selector:

K8s-app: traefik-ingress-lb

Ports:

-protocol: TCP

Port: 80

Name: web

-protocol: TCP

Port: 8080

Name: admin

Type: NodePort

Ui.yaml

Click (here) to collapse or open

ApiVersion: v1

Kind: Service

Metadata:

Name: traefik-web-ui

Namespace: kube-system

Spec:

Selector:

K8s-app: traefik-ingress-lb

Ports:

-name: web

Port: 80

TargetPort: 8580

-

ApiVersion: extensions/v1beta1

Kind: Ingress

Metadata:

Name: traefik-web-ui

Namespace: kube-system

Spec:

Rules:

-host: traefik-ui.local

Http:

Paths:

-path: /

Backend:

ServiceName: traefik-web-ui

ServicePort: web

My-ingress.yaml (here we enable Ingress for elasticsearch and kibana in the cluster)

Click (here) to collapse or open

ApiVersion: extensions/v1beta1

Kind: Ingress

Metadata:

Name: traefik-ingress

Namespace: kube-system

Spec:

Rules:

-host: elasticsearch.donkey

Http:

Paths:

-path: /

Backend:

ServiceName: elasticsearch-logging

ServicePort: 9200

-host: kibana.donkey

Http:

Paths:

-path: /

Backend:

ServiceName: kibana-logging

ServicePort: 5601

III: deployment and verification

1. Create the resource kubectl create-f.

two。 Confirm that pod starts normally through kubectl logs-f

3.traefik dashboard

4. If you need to access outside the kubernetes cluster, you need to set up DNS, or modify the native hosts file. Then access service. Igress directly through host in the service configuration.

Thank you for reading! This is the end of the article on "how to deploy Traefik Ingress in Kubernetes". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report