Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deploy layotto pod in k8s. #722

Closed
kevinten10 opened this issue Jul 13, 2022 · 10 comments · Fixed by #728 or #731
Closed

Deploy layotto pod in k8s. #722

kevinten10 opened this issue Jul 13, 2022 · 10 comments · Fixed by #728 or #731

Comments

@kevinten10
Copy link
Member

kevinten10 commented Jul 13, 2022

What would you like to be added:

添加在k8s中快速部署一个layotto节点的方式。

就像k8s官方提供的示例,仅用一行kubectl即可完成部署:

https://kubernetes.io/zh-cn/docs/tasks/run-application/run-stateless-application-deployment/

kubectl apply -f https://k8s.io/examples/application/deployment.yaml

Why is this needed:

此部署并非layotto作为sidecar的部署方式,而是layotto作为一个单独pod的部署方式。

使用场景主要为:

@kevinten10
Copy link
Member Author

kevinten10 commented Jul 13, 2022

  1. 创建configMap
  2. 创建deploymeny
apiVersion: v1
kind: ConfigMap
metadata:
    name: layotto-runtime-config
data:
  config.json: |
    {
      "servers": [
        {
          "default_log_path": "stdout",
          "default_log_level": "DEBUG",
          "routers": [
            {
              "router_config_name": "actuator_dont_need_router"
            }
          ],
          "listeners": [
            {
              "name": "grpc",
              "address": "0.0.0.0:34904",
              "bind_port": true,
              "filter_chains": [
                {
                  "filters": [
                    {
                      "type": "grpc",
                      "config": {
                        "server_name": "runtime",
                        "grpc_config": {
                          "hellos": {
                            "quick_start_demo": {
                              "type": "helloworld",
                              "hello": "greeting"
                            }
                          },
                          "state": {
                            "state_demo": {
                              "type": "in-memory",
                              "metadata": {
                              }
                            }
                          },
                          "lock": {
                            "lock_demo": {
                              "type": "in-memory",
                              "metadata": {
                              }
                            }
                          },
                          "pub_subs": {
                            "pub_subs_demo": {
                              "type": "in-memory",
                              "metadata": {
                                "consumerID": "1"
                              }
                            }
                          },
                          "sequencer": {
                            "sequencer_demo": {
                              "type": "in-memory",
                              "metadata": {}
                            }
                          },
                          "secret_store": {
                            "secret_demo": {
                              "type": "local.env",
                              "metadata": {
                              }
                            }
                          },
                          "bindings": {
                            "bindings_demo": {
                              "type": "http",
                              "metadata": {
                                "url": "https://mosn.io/layotto"
                              }
                            }
                          },
                          "custom_component": {
                            "helloworld": {
                              "demo": {
                                "type": "in-memory",
                                "metadata": {}
                              }
                            }
                          },
                          "app": {
                            "app_id": "app1",
                            "grpc_callback_port": 9999
                          }
                        }
                      }
                    }
                  ]
                }
              ]
            },
            {
              "name": "actuator",
              "address": "127.0.0.1:34999",
              "bind_port": true,
              "filter_chains": [
                {
                  "filters": [
                    {
                      "type": "proxy",
                      "config": {
                        "downstream_protocol": "Http1",
                        "upstream_protocol": "Http1",
                        "router_config_name": "actuator_dont_need_router"
                      }
                    }
                  ]
                }
              ],
              "stream_filters": [
                {
                  "type": "actuator_filter"
                }
              ]
            }
          ]
        }
      ],
      "tracing": {
        "enable": true,
        "driver": "SOFATracer",
        "config": {
          "generator": "mosntracing",
          "exporter": [
            "stdout"
          ]
        }
      },
      "metrics": {
        "sinks": [
          {
            "type": "prometheus",
            "config": {
              "port": 34903
            }
          }
        ]
      }
    }

---

apiVersion: apps/v1
kind: Deployment
metadata:
  name: layotto-runtime-deployment
  labels:
    app: layotto-runtime-deployment
spec:
  selector:
    matchLabels:
      app: layotto-runtime
  replicas: 1
  template:
    metadata:
      labels:
        app: layotto-runtime
    spec:
      containers:
      - name: layotto-runtime
        image: layotto/layotto:latest
        command: ["/runtime/layotto", "start"]
        args: ["-c", "/runtime/configs/config.json"]
        ports:
        - containerPort: 34904
        volumeMounts:
        - name: runtime-config
          mountPath: /runtime/configs
          readOnly: false
      volumes:
      - name: runtime-config
        configMap:
          name: layotto-runtime-config
          items:
          - key: config.json
            path: config.json

@kevinten10
Copy link
Member Author

kevinten10 commented Jul 13, 2022

使用以上yaml我已经成功部署到k8s中。

configmap配置copy from:https://github.com/mosn/layotto/blob/main/configs/config.json

@kevinten10
Copy link
Member Author

我觉得可以拆成3个yaml,提交到仓库中:

  1. configmap.yaml:提供一份默认配置
  2. deployment.yaml:同以上deployment
  3. layotto-deploy-default.yaml:使用默认configmap,部署以上deployment

这样用户可以直接部署到k8s中,类似:

kubectl apply -f https://layotto/deploy/layotto-deploy-default.yaml

如果想自行修改配置,也可以自己提供一个configmap,再使用上面的deployment.yaml

@seeflood
Copy link
Member

seeflood commented Jul 14, 2022

lgtm. It makes local development much easier !

@Xunzhuo Could u help review this proposal?

@seeflood
Copy link
Member

使用场景主要为:
....
作为独立节点模式,与k8s集成

如何理解“独立节点模式”?

@kevinten10
Copy link
Member Author

因为上面的deployment中只有一个layotto的容器

所以使layotto不是作为sidecar部署

部署一个pod,pod中只有一个layotto容器,我称它为"独立节点模式"

@seeflood
Copy link
Member

@kevinten10 OK. So the benefits of the "standalone mode" is still to make the local development easier, right?
LGTM. Could u help submit a PR for it?

@kevinten10
Copy link
Member Author

Yes, I will submit a PR~

@kevinten10
Copy link
Member Author

kevinten10 commented Jul 19, 2022

@seeflood I plan to put the deployment yaml in this directory, please help to see if it is ok:

/layotto/demo/deploy/k8s/standalone/

  1. default_configmap.yaml
  2. default_deployment.yaml
  3. default_quickstart.yaml (1+2)

@seeflood
Copy link
Member

@kevinten10 LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants