构建你的“胡”

使用麻将,我们可以将多个牌进行组合编排,形成一个完整解决方案的交付架构,在麻将中,我们将它称为“胡”,我们可以使用自己开发的牌配合社区中已有的牌进行自己想要的完整环境组合,重要的是,除了提供您自主实现的灵活度,他们同样拥有最佳实践和快速加速的关键因素。

构思您自己的微服务组合

了解社区现有资源

“胡”

当您构思自己的胡,您可以查看社区的贡献列表,他们均是通过检验的最佳实践。以上是部分流行的组件列表

HuVersionDescription
Simple EKSv0.1.0Quick launch with few lines of yaml.
EKS with Spot instancev0.1.0Quick launch EKS cluster with mixed spot and on-demand instances, as well as handling spot termination, cluster auto scaler and HPA.
Simple ArgoCDv0.1.0Setup ArgoCD on EKS with simple configuration.
Basic CD with ArgoCDv0.1.0Building a modern CD with example applicaiton on GitHub, all you need is a GitHub token.
Perfect Microservice on EKSv0.1.0Implement a handy containerized Microsercices architecture on EKS with all major componnets and demo applications.

“牌”

TilesVersionDescription
Basic Networkv0.0.1The classic network pattern cross multiple availibilty zone with public and private subnets, NAT, etc.
Simple EKSv0.0.1The basic EKS cluster, which uses EKS 1.15 as default version and depends on Network0.
v0.0.5Update EKS default version to 1.16 and expose more options.
EKS on Spotv0.5.0Provison EKS 1.16 as default and using auto scaling group with mixed spot and normal (4:1) instances. Also has Cluster Autoscaler, Horizontal Pod Autoscaler and Spot Instance Handler setup.
EFSv0.1.0The basic EFS conpoment and based on Network0. EFS is a perfect choice as storage option for Kubernetes.
ArgoCDv1.5.2The Argocd0 is basic component to help build up GitOps based CI/CD capability, which depends on Tile - Eks0 & Network0.
Go-Bumblebee-ONLYv0.0.1This is demo application, which can be deploy to Kubernetes cluster to demostrate rich capabilities.
Istiov1.5.4Setup Istio 1.6 on EKS with all necessary features. Managed by Istio operator and Egress Gateway was off by default.
AWS KMSv0.1.0Generate both symmetric key and asymmetric key for down stream applications or services
AWS ElastiCache Redisv5.0.6Setup a redis cluster with replcation group with flexiable options.
AWS Aurora Mtsqlv2.07.2Provision a Aurora MySQL cluster and integrated with Secret Manager to automate secret ratation.
Go-BumbleBee-Jazzv0.7.1Modern cloud native application with tipycal features to try out how great your Kubernetes cluster are.

设计您的微服务组合

在入门环节,我们将通过自己开发的NGINX牌,组合已有的两张牌:aws redis牌,aws Aurora牌组合在一起构建典型的三层架构环境。我们可以通过下图了解麻将的工作机制:

以下是NGINX+redis+mysql三层架构示例下的架构图:

nginx+redis+mysql architecture

创建一个胡repo

NGINX+redis+mysql的“胡”文件夹

$ cd $HOME/ws/local-hu-repo
$ mkdir nginx+redis+mysql/0.1.0

创建胡部署文件

胡部署文件可以定义一个或多个牌,麻将会按照我们的部署文件编排进行交付 创建以下文件nginx-redis-mysql.yaml

apiVersion: mahjong.io/v1alpha1
kind: Deployment
metadata:
  name: nginx-redis-mysql
  version: 0.1.0
spec:
  template:
    tiles:
      tileNginx:
        tileReference: nginx
        tileVersion: 0.0.1
        inputs:
          - name: clusterName
            inputValue: nginx-redis-mysql
          - name: capacity
            inputValue: 3
          - name: capacityInstance
            inputValue: m5.large
          - name: version
            inputValue: 1.16
      tileAWS-ElastiCache-Redis:
        tileReference: AWS-ElastiCache-Redis
        tileVersion: 5.0.6
        dependsOn:
          - tileNginx
        inputs:
          - name: vpc
            # tileInstance.tileName.field
            inputValue: $cdk(tileNginx.Network0.baseVpc)
          - name: subnetIds
            inputValues:
              - $cdk(tileNginx.Network0.privateSubnetId1)
              - $cdk(tileNginx.Network0.privateSubnetId2)
          - name: redisClusterName
            inputValue: mahjong-redis
      tileAWS-Aurora-Mysql:
        tileReference: AWS-Aurora-Mysql
        tileVersion: 2.07.2
        dependsOn:
          - tileNginx
        inputs:
          - name: vpc
            # tileInstance.tileName.field
            inputValue: $cdk(tileNginx.Network0.baseVpc)
          - name: clusterIdentifier
            inputValue: mahjong-mysql
          - name: masterUser
            inputValue: admin
          - name: defaultDatabaseName
            inputValue: testDb

  summary:
    description:
    outputs:
      - name: Nginx Endpoint
        value: $(tileNginx.outputs.nginxEndpoint)
      - name: Redis Endpoint
        value: $(tileAWS-ElastiCache-Redis.outputs.redisEndpoint)
      - name: RDS DatabaseName
        value: $(tileAWS-Aurora-Mysql.outputs.defaultDatabaseName)
      - name: RDS Endpoint
        value: $(tileAWS-Aurora-Mysql.outputs.clusterEndpoint)
    notes: []

完成胡的开发

以上,您已经完成了您自己的胡的开发,胡可以被复用,可以被您定义为您的最佳实践环境。他可以调用任意的牌,组成一个您满意的完整的解决方案架构(例如这个nginx的胡,他调用了您自己创建的nginx的牌,调用了已有的redis和Aurora的牌),麻将的调度层将自动为您调用依赖的牌,并生成CMD命令完成构建,您在胡开发的过程中往往只需要关心您需要什么牌,组成一个什么样的架构…

使用您自定义的胡

执行麻将部署yaml文件

部署到AWSmctl deploy -f ./nginx-redis-mysql.yaml。如果一切顺利你讲会的得到一下结果:

$ mctl deploy -f ./nginx-on-eks.yaml

...

[]  + export KUBECONFIG=/workspace/nginx/lib/nginx/kube.config
[]  + KUBECONFIG=/workspace/nginx/lib/nginx/kube.config
[]  + export WORK_HOME=/workspace/nginx
[]  + WORK_HOME=/workspace/nginx
[]  + export TILE_HOME=/workspace/nginx/lib/nginx
[]  + TILE_HOME=/workspace/nginx/lib/nginx
[]  + export NAMESPACE=default
[]  + NAMESPACE=default
[]  + cd /workspace/nginx
[]  + kubectl apply -f /workspace/nginx/lib/nginx/lib/nginx-on-k8s.yml -n default
[]  deployment.apps/mahjong-nginx-deployment unchanged
[]  service/nginx-service unchanged
[]  + sleep 10
[]  ++ kubectl get svc nginx-service -o 'jsonpath={.status..hostname}'
[]  + echo '{"nginxEndpoint=a3d984b0d065e46feafcc5d9b944b0e7-1722932499.us-east-2.elb.amazonaws.com"}'
[]  Extract outputs: [nginxEndpoint] = [a3d984b0d065e46feafcc5d9b944b0e7-1722932499.us-east-2.elb.amazonaws.com]
[]
[]
[]
[]  Nginx Endpoint = a3d984b0d065e46feafcc5d9b944b0e7-1722932499.us-east-2.elb.amazonaws.com
[]
[]

检查你的Niginx部署结果

$ curl a3d984b0d065e46feafcc5d9b944b0e7-1722932499.us-east-2.elb.amazonaws.com
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

检查你的redis部署结果

检查你的Aurora部署结果

好了,现在您可以快速的使用您的架构进行业务的开发,您还可以把您的胡分享给您的小伙伴,让我们一起使用麻将在最佳实践的环境中专注业务的构建自己的系统。

当然,作为入门级别的实例远不能体现微服务的优势和麻将的强大。请您观看这个例子microservice-all-in-one来体会更强大的麻将的使用。