Use traefik to publish a service in a kuberneters Cluster

Source: Internet
Author: User
Tags etcd amazon ecs k8s

Use traefik to publish a service in a kuberneters Cluster

The previous article has introduced the implementation principle and configuration of k8s ingress. This article will introduce the alternative solution traefik. Before starting the configuration, let's review the implementation scheme of the k8s Service released by ingress. The ingress solution requires the following components:

1. Reverse Proxy Server Load balancer
2. ingress control
3. ingress
The ingress control communicates with the apiserver, monitors pod and service changes, updates the configuration of the Reverse Proxy Server Load balancer, and reloads the configuration of the Reverse Proxy Server Load balancer.

Next let's take a look at traefik, official website address: https://traefik.io/
Traefik (pronounced like traffic) is a modern HTTP reverse proxy and load balancer made to deploy microservices with outputs. it supports several backends (Docker, Swarm mode, Kubernetes, Marathon, Consul, Etcd, Rancher, Amazon ECS, and a lot more) to manage its configuration automatically and dynamically.

Traefik is essentially an http-oriented proxy and Server Load balancer. It supports backend services such as Docker, Swarm mode, Kubernetes, Marathon, Consul, Etcd, Rancher, and Amazon ECS, dynamically manage the configuration files of these services (we can understand that the configuration changes of these backend services are automatically discovered and the service configuration is reloaded)

Is the working principle of traefik:

Traefik features:
1. Go language writing, no additional dependent packages required, fast speed
2. Support for Rest APIs and multiple backend types
3. Support hot configuration file loading without restarting the app Process
4. supports Server load balancer policies such as Round Robin and rebalancer load-balancers.
5. built-in AngularJS Web UI graphical interface
6. Support for https and automatic updating of https certificates
7. Support for websocket, HTTP/2, GRPC, and high-availability clusters
8. network error retries and automatic backend deployment locks are supported (when there are too many backend application errors, auto deployment locks can be performed)

All in all, Traefik can be used as an alternative solution for ingress in the k8s cluster for Service Release. traefik features enough to persuade us to replace ingress with Traefik, next we will start to use Traefik to publish services in the k8s 1.5.2 cluster environment.

1. Run traefik in daemonset mode using the yaml File

# Mkdir traefik
# Cd traefik
# Docker pullk docker. io/traefik # cat traefik. ds. yaml
ApiVersion: extensions/v1beta1
Kind: DaemonSet
Metadata:
Name: traefik-ingress-lb
Namespace: default
Labels:
K8s-app: traefik-ingress-lb
Spec:
Template:
Metadata:
Labels:
K8s-app: traefik-ingress-lb
Name: traefik-ingress-lb
Spec:
TerminationGracePeriodSeconds: 60
HostNetwork: true
RestartPolicy: Always
Containers:
-Image: docker. io/traefik
Name: traefik-ingress-lb
Resources:
Limits:
Cpu: 200 m
Memory: 30Mi
Requests:
Cpu: 100 m
Memory: 20Mi
Ports:
-Name: http
ContainerPort: 80
HostPort: 80
-Name: admin
Container Port: 8081
Args:
--- Web
--- Web. address =: 8081
--- Kubernetes
--- Kubernetes. endpoint = http: // 192.168.115.5: 8080

2. Create webui service and ingress through the yaml File

# Cat ui. yaml
ApiVersion: v1
Kind: Service
Metadata:
Name: traefik-web-ui
Namespace: default
Spec:
Selector:
K8s-app: traefik-ingress-lb
Ports:
-Name: web
Port: 80
TargetPort: 8081
---
ApiVersion: extensions/v1beta1
Kind: Ingress
Metadata:
Name: traefik-web-ui
Namespace: default
Spec:
Rules:
-Host: traefik-ui.local
Http:
Paths:
-Path :/
Backend:
ServiceName: traefik-web-ui
ServicePort: web

3. Create kubernetes-dashboard and frontend ingress through the yaml File

# Cat traefik. ing. yaml
ApiVersion: extensions/v1beta1
Kind: Ingress
Metadata:
Name: traefik-ingress
Spec:
Rules:
-Host: k8s. webui
Http:
Paths:
-Path :/
Backend:
ServiceName: kubernetes-dashboard
ServicePort: 80
-Host: k8s. frontend
Http:
Paths:
-Path :/
Backend:
ServiceName: frontend
ServicePort: 80

3. Create pod and ingress through the above yaml configuration file

# Cd kubernetes/traefik/
# Kubectl get pod
# Kubectl get svc
# Kubectl create-f.

# Kubectl get pod
# Kubectl get svc
# Kubectl get ingress


Iv. Test Application access
Modify the hosts file of the test machine. Because traefik runs in demonset mode, you can direct the hosts record to any node in the k8s cluster.



You can view the taefik graphical interface by accessing port 8081 of any node in the cluster.


In the future, we will study how to publish https services in the k8s cluster.

This article permanently updates link: https://www.bkjia.com/Linux/2018-03/151336.htm

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.