kubectl apply -f k8s:无法识别服务和部署,并且在版本 "v1" 中没有匹配类型 "Service"

kubectl apply -f k8s: is unable to recognize service and deployment and has no matches for kind "Service" in version "v1"

我在 OVH 上安装了 kubernetes 运行 没有问题。但是我最近因为其他问题重新安装了构建服务器并设置了所有东西但是当尝试应用文件时它给出了这个可怕的错误..我错过了什么吗?这个错误的真正含义是什么?

+ kubectl apply -f k8s
unable to recognize "k8s/driver-cluster-ip-service.yaml": no matches for kind "Service" in version "v1"
unable to recognize "k8s/driver-deployment.yaml": no matches for kind "Deployment" in version "apps/v1"
unable to recognize "k8s/driver-mysql-cluster-ip-service.yaml": no matches for kind "Service" in version "v1"
unable to recognize "k8s/driver-mysql-deployment.yaml": no matches for kind "Deployment" in version "apps/v1"
unable to recognize "k8s/driver-mysql-persistent-volume-claim.yaml": no matches for kind "PersistentVolumeClaim" in version "v1"
unable to recognize "k8s/driver-phpmyadmin-cluster-ip-service.yaml": no matches for kind "Service" in version "v1"
unable to recognize "k8s/driver-phpmyadmin-deployment.yaml": no matches for kind "Deployment" in version "apps/v1"

我在 SO 上尝试了所有以前的答案,但 none 对我有用。我不认为我真的需要它,"correct me if i am wrong on that"。我真的很想得到一些帮助。

我已经安装了 kubectl 并获得了我使用的配置文件。 当我执行 kubectl get pods 命令时,我得到了在

之前部署的 pods

这些是一些 yml 文件

k8s/driver-cluster-ip-service.yaml

apiVersion: v1
kind: Service
metadata:
  name: driver-cluster-ip-service
spec:
  type: ClusterIP
  selector:
    component: driver-service
  ports:
    - port: 3000
      targetPort: 8080

k8s/driver-deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: driver-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      component: driver-service
  template:
    metadata:
      labels:
        component: driver-service
    spec:
      containers:
        - name: driver
          image: repo.taxi.com/driver-service
          imagePullPolicy: Always
          ports:
            - containerPort: 8080
      imagePullSecrets:
        - name: taxiregistry

dockerfile

FROM maven:3.6.0-jdk-8-slim AS build
COPY . /home/app/
RUN rm /home/app/controllers/src/main/resources/application.properties
RUN mv /home/app/controllers/src/main/resources/application-kubernetes.properties /home/app/controllers/src/main/resources/application.properties
RUN mvn -f /home/app/pom.xml clean package

FROM openjdk:8-jre-slim
COPY --from=build /home/app/controllers/target/controllers-1.0.jar /usr/local/lib/driver-1.0.0.jar
EXPOSE 8080
ENTRYPOINT ["java","-jar","/usr/local/lib/driver-1.0.0.jar"]

kubectl get pods command

kubectl api-versions

找到解决方案

我必须将二进制文件放在 .kube 文件夹中,该文件夹应该放在根目录中 在我的例子中,我必须首先在根目录中手动创建 .kube 文件夹。

之后,我将我的环境变量设置到该文件夹​​,并将我的配置文件和我的设置也放在那里

然后我不得不与 jenkins 用户共享该文件夹并向 jenkins 组申请权限

Jenkins 不是最新的,所以我不得不重新启动 jenkins 服务器。

而且效果非常好!

记得重启 jenkins 服务器,这样你所做的更改才会对 jenkins 生效。