我的docker-compose
文件如下:
version: '3'
services:
nginx:
build: .
container_name: nginx
ports:
- '80:80'
我的Dockerfile
:
FROM nginx:alpine
我使用了kompose konvert
,它创建了两个名为nginx-deployment.yml
和nginx-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
中。
我运行了这三个命令,但每一个都有不同的错误:
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
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
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"]}'
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
,并且缺少kind
和apiVersion
行。
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- nginx-deployment.yaml
- nginx-service.yaml
kubectl apply -k .