<p>Since the problem mentioned <a href="https://stackoverflow.com/questions/65941558/where-the-default-namespace-is-defined-setup-for-command-kubectl-inside-of-a-pod">here</a>.</p>
<p>I am wondering if it is possible to refer <code>serviceAccountName: &quot;test-sa&quot;</code> which is in namespace <strong>n2</strong> for example to create statefulset in namespace <strong>n1</strong></p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
  name: &quot;{{.Values.ContainerName}}&quot;
  namespace: n1
  labels:
    name: &quot;{{.Values.ReplicaName}}&quot;
    app: &quot;{{.Values.ContainerName}}&quot;
    chart: &quot;{{.Chart.Name}}-{{.Chart.Version}}&quot;
  annotations:
    &quot;helm.sh/created&quot;: {{.Release.Time.Seconds | quote }}
spec:
  selector:
    matchLabels:
      app: &quot;{{.Values.ContainerName}}&quot;
  serviceName: &quot;{{.Values.ContainerName}}&quot;
  replicas: 2
  template:
    metadata:
      labels:
        app: &quot;{{.Values.ContainerName}}&quot;
    spec:
      serviceAccountName: &quot;test-sa&quot;
      securityContext:
        fsGroup: 26
      terminationGracePeriodSeconds: 10
      containers:
      - name: {{.Values.ContainerName}}
        image: &quot;{{.Values.PostgresImage}}&quot;
        ports:
        - containerPort: 5432
          name: postgres
        resources:
          requests:
            cpu: {{default &quot;100m&quot; .Values.Cpu}}
            memory: {{default &quot;100M&quot; .Values.Memory}}
        env:
        - name: PGHOST
          value: /tmp
        - name: PG_PRIMARY_USER
          value: primaryuser
        - name: PG_MODE
          value: set
        - name: PG_PRIMARY_HOST
          value: &quot;{{.Values.PrimaryName}}&quot;
        - name: PG_PRIMARY_PORT
          value: &quot;5432&quot;
        - name: PG_PRIMARY_PASSWORD
          value: &quot;{{.Values.PrimaryPassword}}&quot;
        - name: PG_USER
          value: testuser
        - name: PG_PASSWORD
          value: &quot;{{.Values.UserPassword}}&quot;
        - name: PG_DATABASE
          value: userdb
        - name: PG_ROOT_PASSWORD
          value: &quot;{{.Values.RootPassword}}&quot;
        volumeMounts:
        - name: pgdata
          mountPath: &quot;/pgdata&quot;
          readOnly: false
      volumes:
      - name: pgdata
        persistentVolumeClaim:
          claimName: {{.Values.PVCName}}
</code></pre>

<p>You can't; they need to be in the same namespace.</p>
<p>This is a more general rule.  Whenever one object refers to another they generally need to be in the same namespace, or the target needs to be a cluster-global object.  If a Pod references data in a ConfigMap or mounts a PersistentVolumeClaim, those need to be in the same namespace; if a Service selects Pods by label, those need to be in the same namespace.  There are a couple of exceptions, notably around RBAC, but usually these things need to be deployed together.</p>
<p>In the context of a Helm chart, I'd just create a new ServiceAccount rather than trying to reuse an existing one.  If it uses the typical <code>{{ .Release.Name }}-{{ .Chart.Name }}</code> naming pattern there won't generally be naming conflicts.</p>
