Deploying Resources within a Namespace
Once you have created a namespace, you can start deploying resources, such as pods, services, and deployments, within that namespace. By default, Kubernetes will create resources in the "default" namespace unless you specify a different namespace.
Deploying Resources with a Namespace
To deploy resources within a specific namespace, you can use the --namespace
or -n
flag with the kubectl
command. For example, to create a deployment in the "my-app" namespace, you would run:
kubectl create deployment my-app --image=nginx -n my-app
This will create a new deployment named "my-app" using the NGINX image, and it will be deployed within the "my-app" namespace.
You can also use a YAML configuration file to deploy resources within a namespace. Here's an example YAML file for a Kubernetes service:
apiVersion: v1
kind: Service
metadata:
name: my-service
namespace: my-app
spec:
selector:
app: my-app
ports:
- port: 80
targetPort: 80
In this example, the "namespace" field in the metadata section specifies that the service should be created within the "my-app" namespace.
Viewing Resources within a Namespace
To view the resources within a specific namespace, you can use the --namespace
or -n
flag with the kubectl get
command. For example, to list all the pods in the "my-app" namespace, you would run:
kubectl get pods -n my-app
This will display all the pods that are running within the "my-app" namespace.
By deploying resources within a specific namespace, you can ensure that your applications and services are isolated and secure, and you can easily manage and monitor them within their respective environments.