kubectl没有与版本apps / v1中的kind Service匹配的项 [英] kubectl no matches for kind Service in version apps/v1

查看:782
本文介绍了kubectl没有与版本apps / v1中的kind Service匹配的项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Kubernetes的新手。我正在尝试将应用程序部署到Kubernetes并向公众公开。但是,当我尝试部署配置时,出现以下错误:

I'm new to Kubernetes. I'm making my first ever attempt to deploy an application to Kubernetes and expose it to the public. However, when I try and deploy my configuration, I get this error:


错误:无法识别 deployment.yml:没有与 ;服务在版本 apps / v1中

error: unable to recognize "deployment.yml": no matches for kind "Service" in version "apps/v1"

所以,让我们详细介绍一下。

So, let's run through the details.

我在Ubuntu 18.04。我正在将MiniKube与VirtualBox一起用作HyperVisor驱动程序。以下是所有版本信息:

I'm on Ubuntu 18.04. I'm using MiniKube with VirtualBox as the HyperVisor driver. Here is all the version info:

MiniKube = v1.11.0
VirtualBox = 6.1.0
Kubectl = Client Version 1.18.3, Server Version 1.18.3

我要部署的应用程序是一个超级简单的express.js应用程序

The app I'm trying to deploy is a super-simple express.js app that returns Hello World on request.

const express = require('express');

const app = express();

app.get('/hello', (req, res) => res.send('Hello World'));

app.listen(3000, () => console.log('Running'));

我有一个构建脚本,用于在将所有源文件压缩之前,将快速应用程序部署到docker。然后我有了Dockerfile:

I have a build script I've used for deploying express apps to docker before that zips up all the source files. Then I've got my Dockerfile:

FROM node:12.16.1

WORKDIR /usr/src/app

COPY ./build/TestServer-*.zip ./TestServer.zip
RUN unzip TestServer.zip

RUN yarn

CMD ["yarn", "start"]

所以现在我运行一些命令。 eval $(minikube docker-env)使我使用MiniKube的docker环境,因此不需要将该容器部署到云中。 docker build -t testserver:v1。生成并标记容器。

So now I run some commands. eval $(minikube docker-env) makes me use MiniKube's docker environment so I don't need to deploy this container to the cloud. docker build -t testserver:v1 . builds and tags the container.

现在,让我们转到我的deployment.yml文件:

Now, let's go to my deployment.yml file:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: testserver
spec:
  replicas: 1
  selector:
    matchLabels:
      app: testserver
  template:
    metadata:
      labels:
        app: testserver
    spec:
      containers:
        - name: testserver
          image: testserver:v1
          ports:
            - containerPort: 3000
          env:
          imagePullPolicy: Never
---
apiVersion: apps/v1
kind: Service
metadata:
  name: testserver
spec:
  selector:
    app: testserver
  ports:
    - port: 80
      targetPort: 3000
  type: LoadBalancer

我正在尝试创建一个带有pod和服务的部署以公开它。我确定这里有各种各样的问题,这对我来说是最新的部分,我仍在尝试学习和理解规格。但是,当我尝试使用此配置时,会出现我需要帮助的问题。我运行create命令,并收到错误消息。

I'm trying to create a deployment with a pod and a service to expose it. I'm sure there are various issues in here, this is the newest part to me and I'm still trying to learn and understand the spec. However, the problem I'm asking for help with occurs when I try to use this config. I run the create command, and get the error.

kubectl create -f deployment.yml

deployment.apps/testserver created
error: unable to recognize "deployment.yml": no matches for kind "Service" in version "apps/v1"

其结果是我看到我的应用程序被列为部署和Pod,但是服务部分失败了。我一直在互联网上搜索有关为什么发生这种情况的文档,但我一无所获。

The result of this is I see my app listed as a deployment and as a pod, but the service part has failed. I've been scouring the internet for documentation on why this is happening, but I've got nothing.

推荐答案

apiVersion:v1 而不是 apiVersion:apps / v1 (例如部署)。您可以在官方文档中进行检查。如果要公开您的部署,还需要使用NodePort类型的服务(或ClusterIP)。类型LoadBalancer在minikube中不起作用。这主要用于在云中管理的k8s集群中,其中类型为LoadBalancer的服务将创建负载均衡器(如AWS中的ALB)。

A service is of apiVersion: v1 instead of apiVersion: apps/v1 (like a deployment). You can check it in the official docs. You also need to use a Service of type NodePort (or ClusterIP) if you want to expose your deployment. Type LoadBalancer will not work in minikube. This is mostly used in k8s clusters managed in the cloud where a service of type LoadBalancer will create a loadbalancer (like an ALB in AWS).

检查a的apigroup您可以使用的资源: kubectl api-resources

To check the apigroup of a resource you can use: kubectl api-resources

这篇关于kubectl没有与版本apps / v1中的kind Service匹配的项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆