Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create K8S deployment in specific namespace?

I am using kubectl apply -f https://k8s.io/examples/controllers/nginx-deployment.yaml to create deployment.

I want to create deployment in my namespace examplenamespace.

How can I do this?

like image 622
favok20149 Avatar asked Dec 10 '19 07:12

favok20149


1 Answers

There are three possible solutions.

  1. Specify namespace in the kubectl command:
kubectl apply -f https://k8s.io/examples/controllers/nginx-deployment.yaml -n my-namespace
  1. Specify namespace in your yaml files:
  apiVersion: apps/v1
  kind: Deployment
  metadata:
    name: my-deployment
    namespace: my-namespace
  1. Change default namespace in ~/.kube/config:
apiVersion: v1
kind: Config
clusters:
- name: "k8s-dev-cluster-01"
  cluster:
    server: "https://example.com/k8s/clusters/abc"
    namespace: "my-namespace"
like image 163
Dávid Molnár Avatar answered Oct 22 '22 00:10

Dávid Molnár