使用kubectl apply命令时出现四个不同的错误



我的docker-compose文件如下:

version: '3'
services:
nginx:
build: .
container_name: nginx
ports:
- '80:80'

我的Dockerfile:

FROM nginx:alpine

我使用了kompose konvert,它创建了两个名为nginx-deployment.ymlnginx-service.yml的文件,内容如下。

nginx-deployment.yml:

apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
kompose.cmd: kompose convert
kompose.version: 1.22.0 (955b78124)
creationTimestamp: null
labels:
io.kompose.service: nginx
name: nginx
spec:
replicas: 1
selector:
matchLabels:
io.kompose.service: nginx
strategy: {}
template:
metadata:
annotations:
kompose.cmd: kompose convert
kompose.version: 1.22.0 (955b78124)
creationTimestamp: null
labels:
io.kompose.service: nginx
spec:
containers:
- image: nginx:alpine
name: nginx
ports:
- containerPort: 80
resources: {}
restartPolicy: Always
status: {}

nginx-service.yml:

apiVersion: v1
kind: Service
metadata:
annotations:
kompose.cmd: kompose convert
kompose.version: 1.22.0 (955b78124)
creationTimestamp: null
labels:
io.kompose.service: nginx
name: nginx
spec:
ports:
- name: "80"
port: 80
targetPort: 80
selector:
io.kompose.service: nginx
status:
loadBalancer: {}

我的kustomization.yml:

resources:
- nginx-deployment.yml
- nginx-service.yml

所有文件都在相同的路径/home中。

我运行了这三个命令,但每一个都有不同的错误:

  1. kubectl apply -f kustomization.yml
error: error validating "kustomization.yml": error validating data: [apiVersion not set, kind not set]; if you choose to ignore these errors, turn validation off with --validate=false
  1. kubectl apply -k .
error: accumulating resources: accumulation err='accumulating resources from 'nginx-deployment.yml': evalsymlink failure on '/home/nginx-deployment.yml' : lstat /home/nginx-deployment.yml: no such file or directory': evalsymlink failure on '/home/nginx-deployment.yml' : lstat /home/nginx-deployment.yml: no such file or directory
  1. kubectl apply -f kustomization.yml --validate=false
error: unable to decode "kustomization.yml": Object 'Kind' is missing in '{"resources":["nginx-deployment.yml","nginx-service.yml"]}'
  1. kubectl apply -k . --validate=false
error: accumulating resources: accumulation err='accumulating resources from 'nginx-deployment.yml': evalsymlink failure on '/home/nginx-deployment.yml' : lstat /home/nginx-deployment.yml: no such file or directory': evalsymlink failure on '/home/nginx-deployment.yml' : lstat /home/nginx-deployment.yml: no such file or directory

kubernetes是单个节点。

为什么会出现这些错误,以及如何在此环境中运行容器?

您的Kustomization.yml文件有两个错误。kompose生成的文件具有.yaml扩展名,但您引用的是.yml,并且缺少kindapiVersion行。

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- nginx-deployment.yaml
- nginx-service.yaml
kubectl apply -k .

相关内容

  • 没有找到相关文章

最新更新