简体   繁体   English

在 kubernetes 集群中部署 pod 时出错

[英]Error deploying a pod in a kubernetes cluster

I'm trying to deploy this yaml in my kubernetes cluster into one of my nodes我正在尝试将我的 kubernetes 集群中的这个 yaml 部署到我的一个节点中

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment-1
  labels:
    app: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx
        ports:
        - containerPort: 80

But when I try to deploy it with the command, I get this error message但是当我尝试使用命令部署它时,我收到此错误消息

pi@k8s-master-rasp4:~ $ kubectl apply -f despliegue-nginx.yaml -l kubernetes.io/hostname=k8s-worker-1
error: no objects passed to apply

Anyone knows where the problem could be?任何人都知道问题可能出在哪里?

Thanks谢谢

You are not allowed to use label selector ( -l ) with kubectl apply... .您不能将 label 选择器 ( -l ) 与kubectl apply...一起使用。

Use nodeSelector to assign pods to specific nodes:使用nodeSelector将 pod 分配给特定节点:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment-1
  labels:
    app: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      nodeSelector:
        kubernetes.io/hostname: k8s-worker-1 # <-- updated here!
      containers:
      - name: nginx
        image: nginx
        ports:
        - containerPort: 80

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM