daniel-hutao / Advanced-Kubernetes-Operator

纸质书,2023年1月初出版
45 stars 16 forks source link

第七章 application资源的yaml怎么写 #5

Closed tanlay closed 1 year ago

tanlay commented 1 year ago

书籍150页。 代码逻辑写完,执行make install后,可以查询到crd,但是查询不到application资源,应该是需要编写application资源的yaml文件,然后创建。yaml不知道咋写,各位大佬支援下呢,谢谢!

  1. 查询到applications的crd
    $ kubectl get crd applications.apps.tanlay.com 
    NAME                           CREATED AT
    applications.apps.tanlay.com   2023-01-29T12:57:45
  2. 查询applications资源
    $ kubectl get application
    No resources found in default namespace.
  3. 编写application资源的yaml文件
    apiVersion: apps.tanlay.com/v1
    kind: Application
    metadata:
    name: application-sample
    spec:
    # TODO(user): Add fields here
    deployment:
    ...
    service:
    ...
tanlay commented 1 year ago

已经搞定了。

  1. 编写application的yaml
    apiVersion: apps.tanlay.com/v1
    kind: Application
    metadata:
    name: nginx-sample
    namespace: default
    labels:
    app: nginx
    spec:
    deployment:
    replicas: 3
    selector:
      matchLabels:
        app: nginx
    template:
      metadata:
        labels:
          app: nginx
      spec:
        containers:
          - image: nginx
            name: nginx
            ports:
              - containerPort: 80
    service:
    type: NodePort
    ports:
      - port: 80
        targetPort: 80
        nodePort: 30880
  2. 查看app
    $ kubectl get app
    NAME           AGE
    nginx-sample   10m