在 Ryan Baxter 的Spring On Kubernetes 研讨会之后,我遇到了一个我无法解决的问题。在“部署到 Kubernetes”这一步,生成 depoyment.yaml 和 services.yaml 文件后,我运行
kubectl apply -f ./k8s
我得到验证错误:
error validating "k8s/deployment.yaml": error validating data: the server could not find the requested resource; if you choose to ignore these errors, turn validation off with --validate=false
error validating "k8s/service.yaml": error validating data: the server could not find the requested resource; if you choose to ignore these errors, turn validation off with --validate=false
运行后
kubectl apply -f ./k8s --validate=false
我明白了
error: unable to recognize "k8s/deployment.yaml": no matches for extensions/, Kind=Deployment
service"my-app" created
这是yaml文件:
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: my-app
name: my-app
spec:
replicas: 1
selector:
matchLabels:
app: my-app
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: my-app
spec:
containers:
- image: docker.io/my-id/my-app
name: my-app
resources: {}
status: {}
根据 Harsh 的建议,我将 apiVersion 更改为 apps/v1 并再次运行 kubectl apply 命令。
deployment "my-app" created
service "my-app" configured
根据手表中显示的内容,我运行
kubectl port-forward svc/my-app 8080:80
其中 svc/my-app 显示在手表中。它产生
error: invalid resource name svc/my-app: [may not contain '/']
为了清理,我跑
kubectl delete -f ./k8s
它产生
service "my-app" deleted
Error from server (NotFound): error when stopping "k8s/deployment.yaml": the server could not find the requested resource
我不知道这些问题是我的操作错误还是某些错误引起的。