NATS 中文文档
  • 引言
  • 发布日志
  • NATS 2.0
  • 对比 NATS
  • FAQ
  • NATS Concepts
    • What is NATS
    • Subject-Based Messaging
    • Publish-Subscribe
    • Request-Reply
    • Queue Groups
    • Acknowledgements
    • Sequence Numbers
  • Developing With NATS
    • Introduction
    • Connecting
      • Connecting to the Default Server
      • Connecting to a Specific Server
      • Connecting to a Cluster
      • Connection Name
      • Setting a Connect Timeout
      • Ping/Pong Protocol
      • Turning Off Echo'd Messages
      • Miscellaneous functionalities
    • Automatic Reconnections
      • Disabling Reconnect
      • Set the Number of Reconnect Attempts
      • Avoiding the Thundering Herd
      • Pausing Between Reconnect Attempts
      • Listening for Reconnect Events
      • Buffering Messages During Reconnect Attempts
    • Securing Connections
      • Authenticating with a User and Password
      • Authenticating with a Token
      • Authenticating with an NKey
      • Authenticating with a Credentials File
      • Encrypting Connections with TLS
    • Receiving Messages
      • Synchronous Subscriptions
      • Asynchronous Subscriptions
      • Unsubscribing
      • Unsubscribing After N Messages
      • Replying to a Message
      • Wildcard Subscriptions
      • Queue Subscriptions
      • Draining Messages Before Disconnect
      • Structured Data
    • Sending Messages
      • Including a Reply Subject
      • Request-Reply Semantics
      • Caches, Flush and Ping
      • Sending Structured Data
    • Monitoring the Connection
      • Listen for Connection Events
      • Slow Consumers
    • Tutorials
      • Explore NATS Pub/Sub
      • Explore NATS Request/Reply
      • Explore NATS Queueing
      • Advanced Connect and Custom Dialer in Go
  • NATS Server
    • Installing
    • Running
      • Windows Service
    • Clients
    • Flags
    • Configuration
      • Securing NATS
        • Enabling TLS
        • Authentication
          • Tokens
          • Username/Password
          • TLS Authentication
          • NKeys
          • Authentication Timeout
        • Authorization
        • Multi Tenancy using Accounts
        • Decentralized JWT Authentication/Authorization
          • Account lookup using Resolver
          • Memory Resolver Tutorial
          • Mixed Authentication/Authorization Setup
      • Clustering
        • Configuration
        • TLS Authentication
      • Super-cluster with Gateways
        • Configuration
      • Leaf Nodes
        • Configuration
      • Logging
      • Monitoring
      • System Events
        • System Events & Decentralized JWT Tutorial
    • Managing A NATS Server
      • Upgrading a Cluster
      • Slow Consumers
      • Signals
    • NATS and Docker
      • Tutorial
      • Docker Swarm
      • Python and NGS Running in Docker
  • NATS Tools
    • Introduction
    • mkpasswd
    • nk
    • nsc
      • Basics
      • Streams
      • Services
      • Signing Keys
      • Revocation
      • Managed Operators
    • nats-account-server
      • Basics
      • Inspecting JWTs
      • Directory Store
      • Update Notifications
    • nats-top
      • Tutorial
    • nats-bench
  • NATS Streaming Concepts
    • Introduction
    • Relation to NATS
    • Client Connections
    • Channels
      • Message Log
      • Subscriptions
        • Regular
        • Durable
        • Queue Group
        • Redelivery
    • Store Interface
    • Store Encryption
    • Clustering
      • Supported Stores
      • Configuration
      • Auto Configuration
      • Containers
    • Fault Tolerance
      • Active Server
      • Standby Servers
      • Shared State
      • Failover
    • Partitioning
    • Monitoring
      • Endpoints
  • Developing With NATS Streaming
    • Introduction
    • Connecting to NATS Streaming
    • Publishing to a Channel
    • Receiving Messages from a Channel
    • Durable Subscriptions
    • Queue Subscriptions
    • Acknowledgements
    • The Streaming Protocol
  • NATS Streaming Server
    • Important Changes
    • Installing
    • Running
    • Configuring
      • Command Line Arguments
      • Configuration File
      • Store Limits
      • 持久化
        • 文件存储
        • SQL 存储
      • Securing
    • Process Signaling
    • Windows Service
    • Embedding NATS Streaming Server
    • Docker Swarm
  • NATS Protocol
    • Protocol Demo
    • Client Protocol
      • Developing a Client
    • NATS Cluster Protocol
  • 在 Kubernetes中使用NATS
    • 序言
    • 安装 NATS 和 NATS Streaming
    • 创建一个 Kubernetes 集群
    • 容错(Fault Tolerance)模式下的NATS Streaming 集群
    • NATS 和 Prometheus Operator
    • NATS 集群和证书管理
    • 使用 cfssl 来提高 NATS 集群的安全性
    • 使用负载均衡器(Load Balancer) 为NATS提供外部访问
    • 使用Helm在Digital Ocean 创建一个NATS 超级集群
    • 使用Helm从0到 K8s到 子节点
由 GitBook 提供支持
在本页
  • Google Kubernetes Engine
  • Amazon Kubernetes Service
  • Digital Ocean
  • Azure Kubernetes Service

这有帮助吗?

  1. 在 Kubernetes中使用NATS

创建一个 Kubernetes 集群

上一页安装 NATS 和 NATS Streaming下一页容错(Fault Tolerance)模式下的NATS Streaming 集群

最后更新于4年前

这有帮助吗?

你将通过本文的示例,在不同的云服务产商创建包含3个节点的k8s集群来尝试 NATS。

Google Kubernetes Engine

Use to create a 3 node Kubernetes cluster on us-west2.

通过 在 us-west2 区域创建包含3个节点的 Kubernetes 集群

# Create a 3 node Kubernetes cluster. One node in each of the region's three zones.
gcloud container clusters create nats-k8s-cluster \
  --project $YOUR_GOOGLE_CLOUD_PROJECT \
  --region us-west2 \
  --num-nodes 1 \
  --machine-type n1-standard-2

Note that since this is a regional cluster we are specifying --num-nodes 1 which will create a kubelet on 3 different zones. If you are creating a but want 3 nodes then you have to specify --num-nodes 3.

需要注意的一点是我们在创建集群的时候指定了 --num-nodes 1,这意味着我们将在三个不同的区域创建 kubelet。 如果你要创建的是 并且包含3个节点,你需要指定 --num-nodes 3。

Amazon Kubernetes Service

The is a very helpful tool to manage EKS clusters, you can find more docs on how to set it up .

可以非常方便地创建 EKS 集群,你可以在找到更多配置的文档。

# Create 3 node Kubernetes cluster
eksctl create cluster --name nats-k8s-cluster \
  --nodes 3 \
  --node-type=t3.large \
  --region=eu-west-1

# Get the credentials for your cluster
eksctl utils write-kubeconfig --name $YOUR_EKS_NAME --region eu-west-1

Digital Ocean

doctl kubernetes cluster create nats-k8s-nyc2 --count 3 --region nyc1

Azure Kubernetes Service

# In case not done already, register to use some services:
az login
az provider register -n Microsoft.Network
az provider register -n Microsoft.Storage
az provider register -n Microsoft.Compute
az provider register -n Microsoft.ContainerService

# Create resource group and 3 node cluster
az group create --name nats --location westus
az aks create   --resource-group nats --name nats  --node-count 3 --node-vm-size Standard_DS1_v2
az aks get-credentials --resource-group nats --name nats
kubectl create -n kube-system -f https://raw.githubusercontent.com/dgkanatsios/AksNodePublicIPController/7846c78f77dc5cd4b43629bb5cb7ff3818594aee/deploy.yaml

在这些组件安装完成后,你的(Kubernetes)集群将 为 NATS 提供用于向客户端广播的内部IP:

kubectl get nodes -o wide
NAME                       STATUS   ROLES   AGE     VERSION    INTERNAL-IP   EXTERNAL-IP      OS-IMAGE             KERNEL-VERSION      CONTAINER-RUNTIME
aks-nodepool1-18657977-0   Ready    agent   5d16h   v1.13.12   10.240.0.6    52.191.186.114   Ubuntu 16.04.6 LTS   4.15.0-1060-azure   docker://3.0.7
aks-nodepool1-18657977-1   Ready    agent   5d17h   v1.13.12   10.240.0.4    52.229.11.82     Ubuntu 16.04.6 LTS   4.15.0-1060-azure   docker://3.0.7
aks-nodepool1-18657977-2   Ready    agent   5d17h   v1.13.12   10.240.0.5    13.77.149.235    Ubuntu 16.04.6 LTS   4.15.0-1060-azure   docker://3.0.7

你可以使用 来创建集群:

Using you can create a cluster like this:

使用 你可以像这样创建一个集群:

Note In order to be able to access NATS externally you need to provision public IPs for your cluster installing the following component :

需要注意的是 为了能够从外部访问 NATS,你需要提供公共 IP 来为你的集群安装以下组件:

gcloud
regional
gcloud
跨区域
single-zone cluster
单区域集群
eksctl
here
eksctl
这里
doctl
az
az
dgkanatsios/AksNodePublicIPController
dgkanatsios/AksNodePublicIPController