Configure a Kubernetes namespace pool for Astro Private Cloud

Every Deployment within your Astro Private Cloud installation requires an individual Kubernetes namespace. You can configure a pool of pre-created namespaces to limit Astro Private Cloud access to these namespaces.

When you configure a pool of pre-created namespaces, Astronomer users are required to select a namespace from the pool whenever they create a new Deployment. Once the Deployment is created, Astro Private Cloud marks its corresponding namespace as unavailable. If a Deployment is deleted, its namespace is returned to the pool and is available.

Benefits of pre-created namespaces

A pre-created namespace pool provides the following benefits:

  • It limits the cluster-level permissions your organization needs to give to Astro Private Cloud. Astro Private Cloud requires permissions only for the individual namespaces you configure. Pre-created namespaces are recommended when your organization doesn’t want to give Astro Private Cloud cluster-level permissions in a multi-tenant cluster.
  • It can reduce costs and resource consumption. By default, Astro Private Cloud allows users to create Deployments until there is no more unreserved space in your cluster. If you use a pool, you can limit the number of active Deployments running at a time. This is especially important if you run other Elastic workloads on the same cluster where Astro Private Cloud runs and need to prevent users from accidentally claiming your entire pool of unallocated resources.
Technical Details

When a user creates a new Deployment with the UI or CLI, Astro Private Cloud creates the necessary Airflow components and isolates them in a dedicated Kubernetes namespace. These Airflow components depend on Kubernetes resources, some of which are stored as secrets.

To protect your Deployment Kubernetes secrets, Astronomer uses dedicated service accounts for parts of your Deployment that need to interact with external components. To enable this interaction, Astro Private Cloud needs extensive cluster-level permissions for all namespaces running in a cluster.

In Kubernetes, you can grant service account permissions for an entire cluster, or you can grant permissions for existing namespaces. Astronomer uses cluster-level permissions because, by default, the amount of Deployments to manage is unknown. This level of permissions is appropriate when Astro Private Cloud runs in its own dedicated cluster, but it poses security risks when other applications share the cluster.

For example, consider the deployment orchestrator service, which controls creating, updating, and deleting Deployments. By default, the deployment orchestrator has permissions to interact with secrets, roles, and service accounts for all applications in your cluster. The only way to mitigate this risk is by implementing pre-created namespaces.

Setup

To create a namespace pool you have the following options:

  • Delegate the creation of each namespace, including roles and rolebindings, to the Astronomer Helm chart. This option is suitable for most organizations.
  • Create each namespace manually, including roles and rolebindings. This option is suitable if you need to further restrict Astronomer Kubernetes resource permissions. However, using this methodology to limit permissions can prevent Deployments from functioning as expected.
If you have a separate control plane and data plane(s), following changes in the values.yaml file must be done for the data plane(s) and namespaces must be created in the data plane cluster(s). Each data plane can have their dedicated namespaces.

Prerequisites

  • Helm.
  • kubectl with access to the cluster hosting Astro Private Cloud.

Option 1: Use the Astronomer Helm chart

  1. Set the following configuration in your values.yaml file:
1global:
2 # Set global.manageClusterScopedResources.enabled to false if you don't use ClusterRoles.
3 # manageClusterScopedResources:
4 # enabled: false
5 namespaceManagement:
6 # Configure Vector to gather logs from all available namespaces.
7 manualNamespaceNames:
8 enabled: false
9 # Prevent users from entering namespace names outside the configured pool.
10 namespaceFreeFormEntry:
11 enabled: false
12 namespacePools:
13 enabled: true
14 # Create roles and rolebindings for the namespaces in the pool.
15 createRbac: true
16 namespaces:
17 # Create the namespaces listed in names.
18 create: true
19 names:
20 - <your-namespace-1>
21 - <your-namespace-2>
  1. Save the changes in your values.yaml file and update your Astro Private Cloud. See Apply a config change.

Based on the namespace names that you specified, Astronomer creates the necessary namespaces and Kubernetes resources. These resources have permissions scoped appropriately for most use-cases.

Once you apply your configuration, you should be able to create new Deployments using a namespace from your pre-created namespace pool. You should also be able to see the namespaces you specified inside your cluster resources.

Option 2: Manually create namespaces, roles, and rolebindings

Complete this setup if you want to further limit the namespace permissions that Astronomer provides by default.

Step 1: Configure namespaces

For every namespace you want to add to a pool, you must create a namespace, role, and rolebinding for Astro Private Cloud to access the namespace with. The rolebinding must be scoped to the astronomer-commander service account and the namespace you are creating.

  1. Create a new manifest file for each namespace you want to add to the pool. Replace <your-namespace-name> with the name of the namespace.

    1apiVersion: v1
    2kind: Namespace
    3metadata:
    4 name: <your-namespace-name>
    5---
    6apiVersion: rbac.authorization.k8s.io/v1
    7kind: Role
    8metadata:
    9 name: astronomer-commander
    10 namespace: <your-namespace-name>
    11rules:
    12- apiGroups: ["*"]
    13 resources: ["*"]
    14 verbs: ["list", "watch"]
    15- apiGroups: [""]
    16 resources: ["configmaps"]
    17 verbs: ["create", "delete", "deletecollection", "get", "list", "patch", "update", "watch"]
    18- apiGroups: ["keda.k8s.io"]
    19 resources: ["scaledobjects"]
    20 verbs: ["get", "create", "delete"]
    21- apiGroups: [""]
    22 resources: ["secrets"]
    23 verbs: ["create", "delete", "deletecollection", "get", "list", "patch", "update", "watch"]
    24- apiGroups: [""]
    25 resources: ["namespaces"]
    26 verbs: ["get", "list", "patch", "update", "watch"]
    27- apiGroups: [""]
    28 resources: ["serviceaccounts"]
    29 verbs: ["create", "delete", "get", "patch"]
    30- apiGroups: ["rbac.authorization.k8s.io"]
    31 resources: ["roles"]
    32 verbs: ["*"]
    33- apiGroups: [""]
    34 resources: ["persistentvolumeclaims"]
    35 verbs: ["create", "delete", "deletecollection", "get", "list", "update", "watch", "patch"]
    36- apiGroups: [""]
    37 resources: ["pods"]
    38 verbs: ["get", "list", "watch", "delete", "create", "patch"]
    39- apiGroups: [""]
    40 resources: ["endpoints"]
    41 verbs: ["create", "delete", "get", "list", "update", "watch"]
    42- apiGroups: [""]
    43 resources: ["limitranges"]
    44 verbs: ["create", "delete", "get", "list", "watch", "patch"]
    45- apiGroups: [""]
    46 resources: ["nodes"]
    47 verbs: ["get", "list", "watch"]
    48- apiGroups: [""]
    49 resources: ["nodes/proxy"]
    50 verbs: ["get"]
    51- apiGroups: [""]
    52 resources: ["persistentvolumes"]
    53 verbs: ["create", "delete", "get", "list", "watch", "patch"]
    54- apiGroups: [""]
    55 resources: ["replicationcontrollers"]
    56 verbs: ["list", "watch"]
    57- apiGroups: [""]
    58 resources: ["resourcequotas"]
    59 verbs: ["create", "delete", "get", "list", "patch", "watch"]
    60- apiGroups: [""]
    61 resources: ["services"]
    62 verbs: ["create", "delete", "deletecollection", "get", "list", "patch", "update", "watch"]
    63- apiGroups: ["apps"]
    64 resources: ["statefulsets"]
    65 verbs: ["create", "delete", "get", "list", "patch", "watch"]
    66- apiGroups: ["apps"]
    67 resources: ["deployments"]
    68 verbs: ["create", "delete", "get", "patch","update"]
    69- apiGroups: ["autoscaling"]
    70 resources: ["horizontalpodautoscalers"]
    71 verbs: ["list", "watch"]
    72- apiGroups: ["batch"]
    73 resources: ["jobs"]
    74 verbs: ["list", "watch", "create", "delete", "get"]
    75- apiGroups: ["batch"]
    76 resources: ["cronjobs"]
    77 verbs: ["create", "delete", "get", "list", "patch", "watch"]
    78- apiGroups: ["extensions"]
    79 resources: ["daemonsets", "replicasets"]
    80 verbs: ["list", "watch"]
    81- apiGroups: ["extensions"]
    82 resources: ["deployments"]
    83 verbs: ["create", "delete", "get", "list", "patch", "update", "watch"]
    84- apiGroups: [""]
    85 resources: ["events"]
    86 verbs: ["create", "delete", "patch", "list"]
    87- apiGroups: ["extensions"]
    88 resources: ["ingresses"]
    89 verbs: ["create", "delete", "deletecollection", "get", "list", "patch", "update", "watch"]
    90- apiGroups: ["extensions"]
    91 resources: ["ingresses/status"]
    92 verbs: ["update"]
    93- apiGroups: ["networking.k8s.io"]
    94 resources: ["ingresses"]
    95 verbs: ["get", "create", "delete", "patch"]
    96- apiGroups: ["networking.k8s.io"]
    97 resources: ["ingresses/status"]
    98 verbs: ["update"]
    99- apiGroups: ["networking.k8s.io"]
    100 resources: ["networkpolicies"]
    101 verbs: ["create", "delete", "get", "patch"]
    102- apiGroups: ["rbac.authorization.k8s.io"]
    103 resources: ["rolebindings"]
    104 verbs: ["create", "delete", "get", "patch"]
    105- apiGroups: ["authentication.k8s.io"]
    106 resources: ["tokenreviews"]
    107 verbs: ["create", "delete"]
    108- apiGroups: ["authorization.k8s.io"]
    109 resources: ["subjectaccessreviews"]
    110 verbs: ["create", "delete"]
    111- apiGroups: ["policy"]
    112 resources: ["poddisruptionbudgets"]
    113 verbs: ["create", "delete", "get"]
    114- apiGroups: [""]
    115 resources: ["pods/log"]
    116 verbs: ["get", "list"]
    117- apiGroups: [""]
    118 resources: ["pods/exec"]
    119 verbs: ["get", "create"]
    120---
    121apiVersion: rbac.authorization.k8s.io/v1
    122kind: RoleBinding
    123metadata:
    124 name: deployment-commander-rolebinding
    125 namespace: <your-namespace-name>
    126roleRef:
    127 apiGroup: rbac.authorization.k8s.io
    128 kind: Role
    129 name: astronomer-commander # Should match name of Role
    130subjects:
    131- namespace: astronomer # Should match namespace where SA lives
    132 kind: ServiceAccount
    133 name: astronomer-commander # Should match service account name
  2. Save this file and name it <your-namespace-name>.yaml.

  3. For each namespace you will configure in global.namespaceManagement.namespacePools.namespaces.names, run kubectl apply -f <your-namespace-name>.yaml.

Step 2: Configure a namespace pool in Astronomer

  1. Set the following values in your values.yaml file, making sure to specify all of the namespaces you created in the namespaces.names object:

    1global:
    2 namespaceManagement:
    3 # Configure Vector to gather logs from all available namespaces.
    4 manualNamespaceNames:
    5 enabled: false
    6 # Prevent users from entering namespace names outside the configured pool.
    7 namespaceFreeFormEntry:
    8 enabled: false
    9 namespacePools:
    10 enabled: true
    11 # Don't create roles or rolebindings for the namespaces in the pool.
    12 createRbac: false
    13 namespaces:
    14 # Don't create namespaces because you created them manually.
    15 create: false
    16 names:
    17 - <your-namespace-1>
    18 - <your-namespace-2>
  2. Save the changes in your values.yaml and update Astro Private Cloud. See Apply a config change.

Create Deployments in pre-created namespaces

After you enable the pre-created namespace pool, the UI shows the namespaces you registered as options when you create a new Deployment.

Kubernetes namespace option in the UI

When you create Deployments with the CLI, you are prompted to select one of the available namespaces for your new Deployment.

If no namespaces are available, the UI and CLI show an error message when you try to create a Deployment. Delete the Deployment associated with the namespace to return the namespace to the pool.

Advanced settings

If your namespace configurations require more granularity, use the following settings in your values.yaml file.

Mixing global and advanced settings might result in unexpected behavior. If you use the advanced settings, Astronomer recommends that you set global.namespaceManagement.namespacePools.enabled to false.

SettingDescription
global.namespaceManagement.manualNamespaceNames.enabledExpands the Vector log collector rule to look for Deployment component logs in all namespaces.
global.clusterRolesWhen set to false, Astronomer doesn’t create a ClusterRole for the deployment orchestrator.
global.manageClusterScopedResources.enabledWhen set to false, Astronomer doesn’t create or update cluster-scoped resources.
global.rbac.enabledWhen set to false, the platform doesn’t create roles, rolebindings, or service accounts. You must define default roles for the default Kubernetes service account to continue with the platform installation. See Bring your own Kubernetes service accounts for setup steps.
astronomer.houston.config.deployments.namespaceManagement.manualNamespaceNames.enabledWhen set to true, the Astro Private Cloud UI adds a dropdown field for namespace selection to the Deployment settings.
astronomer.houston.config.deployments.namespaceManagement.preCreatedNamespacesLists the namespaces that you manually created for the namespace pool.
astronomer.commander.envInjects an environment variable for the deployment orchestrator that prevents namespace creation when a new Deployment starts. Set the name to COMMANDER_MANUAL_NAMESPACE_NAMES and the value to "true".

When using these settings, Astronomer recommends enabling hard deletion for Deployments.

In the following example values.yaml file, these settings are configured so that you don’t configure namespace pools at a global level:

1global:
2 namespaceManagement:
3 # Configure Vector to gather logs from all available namespaces.
4 manualNamespaceNames:
5 enabled: true
6 namespacePools:
7 enabled: false
8 clusterRoles: false
9
10astronomer:
11 houston:
12 config:
13 deployments:
14 namespaceManagement:
15 # Enable manual namespace names.
16 manualNamespaceNames:
17 enabled: true
18 # Specify pre-created namespace names.
19 preCreatedNamespaces:
20 - name: <namespace-name-1>
21 - name: <namespace-name-2>
22 - name: <namespace-name-x>
23
24 deploymentLifecycle:
25 # Allow immediate reuse of a namespace after hard deletion.
26 hardDeleteDeployment:
27 enabled: true
28
29 commander:
30 env:
31 - name: "COMMANDER_MANUAL_NAMESPACE_NAMES"
32 value: "true"

Troubleshoot namespace pools

My Deployment is in an unknown state

If a Deployment isn’t active, check the deployment orchestrator Pods to confirm they executed the Deployment commands successfully. When using a pre-created namespace pool with scoped roles, it’s possible that the astronomer-commander service account doesn’t have the permissions necessary to perform a required action. When the deployment orchestrator succeeds, it shows the following notification:

time="2021-07-21T16:30:23Z" level=info msg="releaseName <release-name>, chart astronomer-ee/airflow, chartVersion 0.20.0, namespace <your-namespace-name>" function=InstallRelease package=helm
time="2021-07-21T16:30:23Z" level=info msg="CHART PATH: /home/commander/.cache/helm/repository/airflow- 0.20.0.tgz\n" function=InstallRelease package=helm

When the deployment orchestrator fails, it shows messages like the following:

time="2022-02-17T22:52:40Z" level=error msg="serviceaccounts is forbidden: User \"system:serviceaccount:astronomer:astronomer-commander\" cannot create resource \"serviceaccounts\" in API group \"\" in the namespace <your-namespace>" function=InstallDeployment package=kubernetes

This error shows that the deployment orchestrator couldn’t create the service accounts in the pre-created namespaces, so you need to update the roles.

My namespace isn’t returning to the pool

If you’re not using hard deletion, it can take several days for pre-created namespaces to become available after the associated Deployment is deleted. To enable hard deletes, see Delete a Deployment.

My Deployments using NFS deploys stopped working

NFS deploys don’t work if you both use namespace pools and set global.clusterRoles to false in your values.yaml file.