Consul Chinese document - consul open k8s internal and external service discovery

osc_ emo7t12i 2021-01-21 10:59:14
consul chinese document consul open

Consul Chinese document
Reprint please indicate , If you like, please click three times

List of articles

Consul special column —Consul Working principle and landing practice

Consul Chinese document 1.9


To improve the availability of production , Reduce manual O & M costs , Now let's use k8s Choreography and deployment has become a trend . As we gradually K8s When migrating to , How to solve the current transition Architecture Service discovery The question of ?

( Getting through service discovery may just be the first step , In the future, we may do cross platform service governance based on service discovery , We will analyze this situation later )

This article is mainly based on Consul Solutions for , To achieve Not K8s Service( Running on the K8s Outside ) And Native K8s Service Between the Service discovery and Interoperability .

Simply speaking , Is to achieve K8s Outside the cluster The application can find calling K8s Service , meanwhile K8s Inside The application can call in the cluster native service Call services outside the cluster as well .

Consul Based on this scenario , Yes Consul-Sync Components , To achieve Consul and Kubernetes A solution for services to synchronize with each other .

One 、 Sync Kubernetes and Consul service

The synchronization function consists of consul-k8s project Provide , Can pass Consul Helm Chart Automatic installation and configuration .

1.1 Sync Kubernetes services To Consul

Consul Sync Components can be synchronized automatically Kubernetes Service Sign up to Consul Catalog in .

synchronous K8s services, Make it possible for users to Consul Native service discovery is used to discover and connect services K8s In the service , Such as DNS or HTTP.

( Span K8s Service discovery of cluster , It can also be done like this )

Synchronized services will be registered to k8s-sync Node , It's not a real Consul node , Unlike Consul Client Node to register and monitor services . Relative , k8s-sync What the node monitors is K8s, And synchronize services to Consul.

synchronous Service type 、 Synchronous namespace 、 synchronous Service Can be configured 、 Comments to set , In the future, I will write a separate article to explain the configuration .

1.1.1 Synchronization supports Kubernetes Services type

PS: It is worth noting that , By default K8s Virtual... Used within IP, So not all Services All types can be accessed outside the cluster .

At present, there are four kinds of support K8s services Sync : NodePort、LoadBalancer、External IPs、Cluster IP, If the service type does not belong to these four , Will not be synchronized . The synchronization of each type is as follows , I made a table .

Service type NodePort LoadBalancer External IPs Cluster IP
The service name service name + namespace service name + namespace service name + namespace service name + namespace
Number of service instances Pod Count External IP Count External IP Count Pod Count
Service instance address (Address) Node External IP LB External IP External IP Pod IP
Service instance port (Port) Node port first port first port first target port

PS: About the service name 、 Service port 、 Service Tag 、 Service Metadata All of them can actually pass through Consul Annotation or configuration to customize , In the next section, we will introduce .

1.1.2 Preview of synchronization

I've prepared three examples , One of me Nginx Deployment , Three copies of , Colleagues create three types of Service , Respectively ClusterIP、NodePort、LoadBalancer, Let's take a look at their synchronization effects .
Nginx Service
Take a look Consul In the cluster , Service after synchronization .
Consul Sync K8s service

- Cluster-IP
Generate three service instances .
 Insert picture description here

- NodePort
Generate three service instances , Each service instance IP Corresponding Node Public network IP

- LoadBalancer(External IP)
LoadBalancer type , The official website said that a service instance was generated , But after I measured , When I am LB There are two Ip when ( Like an intranet , A public network ), This situation produces two service instances , This is the sum of External Ip It's a bit similar .
lb type

1.1.3 matters needing attention About External IPs

External IP Not at all K8s Service type , It's a kind of Specified external Ip The situation of , If a service specifies External Ip, So this service can also be synchronized .

In this case , External Ip It might have been set up by other systems , however External Ips It must be resolved by other service discovery system , Don't be empty IP. About ClusterIP

But notice this type , Under normal circumstances , Pod Ip It's empty Ip, Is not accessible outside the cluster . If you don't want to synchronize this ClusterIP type , Can pass Helm Turn off the configuration in syncClusterIPServices=false.

In fact, in the case of public cloud , commonly K8s Internal IP Can use directly VPC IP, So in the cluster 、 The network outside the cluster is flat , Can communicate with each other .

1.2 Sync Consul service To Kubernetes

about Consul Every one of them Service Will be in K8s Create a ExternalName Service,external name by Consul DNS name . for example Consul There is a name in foo Of Service , So created K8s Service Will be as follows

apiVersion: v1
kind: Service
name: foo
annotations: "false"
consul: "true"
externalName: foo.service.consul
type: ExternalName

Be careful : foo.service.consul Need to use Consul DNS Can be resolved to Oh .

//  Can be replaced with Consul Service,  If Consul It's deployed in K8s Medium .
dig @ -p 8600 redis.service.dc1.consul. ANY

Add : All synchronized services will bring consul: "true" , So it's easy to screen out .

1.2.1 Sync preview

Let me show you an example , stay Consul In the cluster , There will be a Consul Service , Let's take it as an example to see what happens after synchronization .

Consul service

Take a look Kubernetes After synchronization Consul service .
Consul The service is synchronized to k8s

1.2.2 Asynchronous scheme

Actually from Consul towards Kubernetes Synchronization is not necessary , It can be based on Kubernetes Of DNS programme , To configure Consul DNS. For example, if you're using KubeDNS see stub-domain configuration, If in use CoreDNS, May refer to proxy configuration.

Once configured Consul DNS, When we use <consul-service-name>.service.consul When the format initiates a request ,Consul DNS Will be parsed into Consul Inside Service, All of the K8s All spaces can work .

Of course , If you want to pass service-name Format to access , It still has to be synchronized .

About Consul DNS stay K8s It can be used for reference : Consul DNS on Kubernetes

Two 、Consul Sync install

Limited to the length of the article , Let's put it in the next article Consul Sync Configuration and related installation of .

3、 ... and 、 summary

3.1 Why sync Kubernetes services To Consul?

take Kubernetes Service Synchronize to Consul Catalog, You can make Consul All nodes in the cluster can access these services . Moreover, this scheme can be used as a variety of K8s Cluster service discovery scheme . For non K8s node ( Outside the cluster ) Can pass Consul DNS perhaps HTTP API Get service information .

3.2 Why sync Consul services To Kubernetes?

After synchronization ,K8s Services within can be called like K8s It's the same as in-house service , Call external services . It's also similar to the automation of external changes like some databases .

Four 、 Reference documents

  1. Syncing Kubernetes and Consul Services
  2. Announcing First-Class Kubernetes Support for HashiCorp Products
  3. Announcing HashiCorp Consul + Kubernetes
  4. Consul DNS on Kubernetes
本文为[osc_ emo7t12i]所创,转载请带上原文链接,感谢

  1. 【计算机网络 12(1),尚学堂马士兵Java视频教程
  2. 【程序猿历程,史上最全的Java面试题集锦在这里
  3. 【程序猿历程(1),Javaweb视频教程百度云
  4. Notes on MySQL 45 lectures (1-7)
  5. [computer network 12 (1), Shang Xuetang Ma soldier java video tutorial
  6. The most complete collection of Java interview questions in history is here
  7. [process of program ape (1), JavaWeb video tutorial, baidu cloud
  8. Notes on MySQL 45 lectures (1-7)
  9. 精进 Spring Boot 03:Spring Boot 的配置文件和配置管理,以及用三种方式读取配置文件
  10. Refined spring boot 03: spring boot configuration files and configuration management, and reading configuration files in three ways
  11. 精进 Spring Boot 03:Spring Boot 的配置文件和配置管理,以及用三种方式读取配置文件
  12. Refined spring boot 03: spring boot configuration files and configuration management, and reading configuration files in three ways
  13. 【递归,Java传智播客笔记
  14. [recursion, Java intelligence podcast notes
  15. [adhere to painting for 386 days] the beginning of spring of 24 solar terms
  16. K8S系列第八篇(Service、EndPoints以及高可用kubeadm部署)
  17. K8s Series Part 8 (service, endpoints and high availability kubeadm deployment)
  18. 【重识 HTML (3),350道Java面试真题分享
  19. 【重识 HTML (2),Java并发编程必会的多线程你竟然还不会
  20. 【重识 HTML (1),二本Java小菜鸟4面字节跳动被秒成渣渣
  21. [re recognize HTML (3) and share 350 real Java interview questions
  22. [re recognize HTML (2). Multithreading is a must for Java Concurrent Programming. How dare you not
  23. [re recognize HTML (1), two Java rookies' 4-sided bytes beat and become slag in seconds
  24. 造轮子系列之RPC 1:如何从零开始开发RPC框架
  25. RPC 1: how to develop RPC framework from scratch
  26. 造轮子系列之RPC 1:如何从零开始开发RPC框架
  27. RPC 1: how to develop RPC framework from scratch
  28. 一次性捋清楚吧,对乱糟糟的,Spring事务扩展机制
  29. 一文彻底弄懂如何选择抽象类还是接口,连续四年百度Java岗必问面试题
  30. Redis常用命令
  31. 一双拖鞋引发的血案,狂神说Java系列笔记
  32. 一、mysql基础安装
  33. 一位程序员的独白:尽管我一生坎坷,Java框架面试基础
  34. Clear it all at once. For the messy, spring transaction extension mechanism
  35. A thorough understanding of how to choose abstract classes or interfaces, baidu Java post must ask interview questions for four consecutive years
  36. Redis common commands
  37. A pair of slippers triggered the murder, crazy God said java series notes
  38. 1、 MySQL basic installation
  39. Monologue of a programmer: despite my ups and downs in my life, Java framework is the foundation of interview
  40. 【大厂面试】三面三问Spring循环依赖,请一定要把这篇看完(建议收藏)
  41. 一线互联网企业中,springboot入门项目
  42. 一篇文带你入门SSM框架Spring开发,帮你快速拿Offer
  43. 【面试资料】Java全集、微服务、大数据、数据结构与算法、机器学习知识最全总结,283页pdf
  44. 【leetcode刷题】24.数组中重复的数字——Java版
  45. 【leetcode刷题】23.对称二叉树——Java版
  46. 【leetcode刷题】22.二叉树的中序遍历——Java版
  47. 【leetcode刷题】21.三数之和——Java版
  48. 【leetcode刷题】20.最长回文子串——Java版
  49. 【leetcode刷题】19.回文链表——Java版
  50. 【leetcode刷题】18.反转链表——Java版
  51. 【leetcode刷题】17.相交链表——Java&python版
  52. 【leetcode刷题】16.环形链表——Java版
  53. 【leetcode刷题】15.汉明距离——Java版
  54. 【leetcode刷题】14.找到所有数组中消失的数字——Java版
  55. 【leetcode刷题】13.比特位计数——Java版
  56. oracle控制用户权限命令
  57. 三年Java开发,继阿里,鲁班二期Java架构师
  58. Oracle必须要启动的服务
  59. 万字长文!深入剖析HashMap,Java基础笔试题大全带答案
  60. 一问Kafka就心慌?我却凭着这份,图灵学院vip课程百度云