我正在尝试执行kubectl create deployment
命令时定义名称空间名称吗?
这是我尝试过的:
kubectl create deployment test --image=banu/image1 namespace=test
这不起作用。
我想使用群集本身ClusterIP
中的for that given namespace
服务公开此部署吗?如何使用kubectl
命令行执行此操作?
答案 0 :(得分:1)
您可以指定-n
或--namespace
选项。
kubectl create deployment test --image=nginx --namespace default --dry-run -o yaml
并查看结果部署Yaml。
使用kubectl run
kubectl run test --namespace test --image nginx --port 9090 --dry-run -o yaml
答案 1 :(得分:0)
使用-n test代替namespace = test
带有nginx图像的示例:
$ kubectl create deployment nginx --image=nginx -n test
deployment.apps/nginx created
$ kubectl get deploy -n test
NAME READY UP-TO-DATE AVAILABLE AGE
nginx 1/1 1 1 8s
在第二种情况下,您需要创建服务并从部署中定义标签。
您可以通过runnig找到正确的标签,例如:
kubectl -n test describe deploy test |grep Labels:
并应用以下服务:
apiVersion: v1
kind: Service
metadata:
name: test-svc
namespace: test
spec:
ports:
- name: test
port: 80 # Change this port
protocol: TCP
type: ClusterIP
selector:
# Here you need to define output from previous step
答案 2 :(得分:0)
kubectl create ns test
ns代表名称空间,因此使用kubectl表示要创建名称为test的名称空间
kubectl create deployment test --image=banu/image1 -n test
标志-n代表名称空间,您这样对Kubernetes说,与该部署相关的所有资源都将位于测试名称空间下
kubectl get all -n test
--namespace and -n is the same things