Невозможно использовать BackendConfig на GKE - PullRequest
1 голос
/ 29 апреля 2020

У меня есть приложение, которое я могу развернуть в kubernetes (Google Kubernetes Engine), к которому я пытаюсь добавить CDN Google. Для этого я добавляю BackendConfig. Но когда мой конвейер gitlab пытается применить его, он возвращает следующую ошибку:

$ kubectl apply -f backend-config.yaml Ошибка с сервера (запрещено): ошибка при получении текущей конфигурации: Resource: "cloud.google.com/v1beta1, Resource = backendconfigs", GroupVersionKind: "cloud.google.com/v1beta1, Kind = BackendConfig"

У меня есть серьезные подозрения, что учетная запись, которую использует конвейер У пользователя under недостаточно прав для доступа к внутренним конфигурациям. Будучи новичком в k8s и gke, я не уверен, как это исправить. Тем более, что я не могу найти, какое разрешение требуется для этого.

Редактировать

Я добавил kubectl get backendconfigs в свой конвейер, и это не удалось с той же ошибкой. При запуске из моей среды gcloud sdk работает та же команда.

Обратите внимание, что кластер управляется Gitlab и использует RBA C. Насколько я понимаю, gitlab создает учетные записи служб для каждого пространства имен в k8s с ролью edit.

Редактировать 2

Добавлено ClusterRole и ClusterRoleBinding на основе ответа Аргьи.

Вывод $ kubectl get crd

NAME                                           CREATED AT
backendconfigs.cloud.google.com                2020-01-09T15:37:27Z
capacityrequests.internal.autoscaling.k8s.io   2020-04-28T11:15:26Z
certificaterequests.cert-manager.io            2020-01-15T06:53:47Z
certificates.cert-manager.io                   2020-01-15T06:53:48Z
challenges.acme.cert-manager.io                2020-01-15T06:53:48Z
challenges.certmanager.k8s.io                  2020-01-09T15:47:01Z
clusterissuers.cert-manager.io                 2020-01-15T06:53:48Z
clusterissuers.certmanager.k8s.io              2020-01-09T15:47:01Z
issuers.cert-manager.io                        2020-01-15T06:53:48Z
issuers.certmanager.k8s.io                     2020-01-09T15:47:01Z
managedcertificates.networking.gke.io          2020-01-09T15:37:53Z
orders.acme.cert-manager.io                    2020-01-15T06:53:48Z
orders.certmanager.k8s.io                      2020-01-09T15:47:01Z
scalingpolicies.scalingpolicy.kope.io          2020-01-09T15:37:53Z
updateinfos.nodemanagement.gke.io              2020-01-09T15:37:53Z

Вывод kubectl describe crd backendconfigs.cloud.google.com

Name:         backendconfigs.cloud.google.com
Namespace:    
Labels:       <none>
Annotations:  <none>
API Version:  apiextensions.k8s.io/v1beta1
Kind:         CustomResourceDefinition
Metadata:
  Creation Timestamp:  2020-01-09T15:37:27Z
  Generation:          1
  Resource Version:    198
  Self Link:           /apis/apiextensions.k8s.io/v1beta1/customresourcedefinitions/backendconfigs.cloud.google.com
  UID:                 f0bc780a-32f5-11ea-b7bd-42010aa40111
Spec:
  Conversion:
    Strategy:  None
  Group:       cloud.google.com
  Names:
    Kind:       BackendConfig
    List Kind:  BackendConfigList
    Plural:     backendconfigs
    Singular:   backendconfig
  Scope:        Namespaced
  Validation:
    Open APIV 3 Schema:
      Properties:
        API Version:
          Description:  APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#resources
          Type:         string
        Kind:
          Description:  Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds
          Type:         string
        Metadata:
          Type:  object
        Spec:
          Description:  BackendConfigSpec is the spec for a BackendConfig resource
          Properties:
            Cdn:
              Description:  CDNConfig contains configuration for CDN-enabled backends.
              Properties:
                Cache Policy:
                  Description:  CacheKeyPolicy contains configuration for how requests to a CDN-enabled backend are cached.
                  Properties:
                    Include Host:
                      Description:  If true, requests to different hosts will be cached separately.
                      Type:         boolean
                    Include Protocol:
                      Description:  If true, http and https requests will be cached separately.
                      Type:         boolean
                    Include Query String:
                      Description:  If true, query string parameters are included in the cache key according to QueryStringBlacklist and QueryStringWhitelist. If neither is set, the entire query string is included and if false the entire query string is excluded.
                      Type:         boolean
                    Query String Blacklist:
                      Description:  Names of query strint parameters to exclude from cache keys. All other parameters are included. Either specify QueryStringBlacklist or QueryStringWhitelist, but not both.
                      Items:
                        Type:  string
                      Type:    array
                    Query String Whitelist:
                      Description:  Names of query string parameters to include in cache keys. All other parameters are excluded. Either specify QueryStringBlacklist or QueryStringWhitelist, but not both.
                      Items:
                        Type:  string
                      Type:    array
                  Type:        object
                Enabled:
                  Type:  boolean
              Required:
                enabled
              Type:  object
            Connection Draining:
              Description:  ConnectionDrainingConfig contains configuration for connection draining. For now the draining timeout. May manage more settings in the future.
              Properties:
                Draining Timeout Sec:
                  Description:  Draining timeout in seconds.
                  Format:       int64
                  Type:         integer
              Type:             object
            Iap:
              Description:  IAPConfig contains configuration for IAP-enabled backends.
              Properties:
                Enabled:
                  Type:  boolean
                Oauthclient Credentials:
                  Description:  OAuthClientCredentials contains credentials for a single IAP-enabled backend.
                  Properties:
                    Client ID:
                      Description:  Direct reference to OAuth client id.
                      Type:         string
                    Client Secret:
                      Description:  Direct reference to OAuth client secret.
                      Type:         string
                    Secret Name:
                      Description:  The name of a k8s secret which stores the OAuth client id & secret.
                      Type:         string
                  Required:
                    secretName
                  Type:  object
              Required:
                enabled
                oauthclientCredentials
              Type:  object
            Security Policy:
              Type:  object
            Session Affinity:
              Description:  SessionAffinityConfig contains configuration for stickyness parameters.
              Properties:
                Affinity Cookie Ttl Sec:
                  Format:  int64
                  Type:    integer
                Affinity Type:
                  Type:  string
              Type:      object
            Timeout Sec:
              Format:  int64
              Type:    integer
          Type:        object
        Status:
          Type:  object
  Version:       v1beta1
  Versions:
    Name:     v1beta1
    Served:   true
    Storage:  true
Status:
  Accepted Names:
    Kind:       BackendConfig
    List Kind:  BackendConfigList
    Plural:     backendconfigs
    Singular:   backendconfig
  Conditions:
    Last Transition Time:  2020-01-09T15:37:27Z
    Message:               no conflicts found
    Reason:                NoConflicts
    Status:                True
    Type:                  NamesAccepted
    Last Transition Time:  <nil>
    Message:               the initial names have been accepted
    Reason:                InitialNamesAccepted
    Status:                True
    Type:                  Established
  Stored Versions:
    v1beta1
Events:  <none>

1 Ответ

2 голосов
/ 29 апреля 2020

Создание ClusterRole и ClusterRoleBinding для служебной учетной записи example-sa в пространстве имен example-namespace

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: backendconfig-role
rules:
- apiGroups: ["cloud.google.com"]
  resources: ["backendconfigs"]
  verbs: ["get", "watch", "list", "create", "delete"]

---

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: backendconfig-rolebinding
subjects:
- kind: ServiceAccount
  name: example-sa 
  namespace: example-namespace
roleRef:
  kind: ClusterRole
  name: backendconfig-role
  apiGroup: rbac.authorization.k8s.io

Для проверки применяется разрешение

kubectl auth can-i get backendconfigs --as=system:serviceaccount:example-namespace:example-sa -n example-namespace
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...