0

在 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

我不知道这些问题是我的操作错误还是某些错误引起的。

4

2 回答 2

0

保存并部署此文件:kubectl apply -f filename.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  creationTimestamp: null
  labels:
    app: k8s-demo-app
  name: k8s-demo-app
spec:
  replicas: 1
  selector:
    matchLabels:
      app: k8s-demo-app
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: k8s-demo-app
    spec:
      containers:
      - image: harbor.workshop.demo.ryanjbaxter.com/user1/k8s-demo-app
        name: k8s-demo-app
        resources: {}
status: {}
---
apiVersion: v1
kind: Service
metadata:
  creationTimestamp: null
  labels:
    app: k8s-demo-app
  name: k8s-demo-app
spec:
  ports:
  - name: 80-8080
    port: 80
    protocol: TCP
    targetPort: 8080
  selector:
    app: k8s-demo-app
  type: ClusterIP
status:
  loadBalancer: {}
于 2020-04-17T05:03:43.280 回答
0

在 Harsh 和 Chanseok 的帮助下,我升级了 gcloud 组件,而 kubectl 就是其中之一。

kubectl version

Client Version: version.Info{Major:"1", Minor:"17", GitVersion:"v1.17.2", GitCommit:"59603c6e503c87169aea6106f57b9f242f64df89", GitTreeState:"clean", BuildDate:"2020-01-18T23:30:10Z", GoVersion:"go1.13.5", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"17", GitVersion:"v1.17.3", GitCommit:"06ad960bfd03b39c8310aaf92d1e7c12ce618213", GitTreeState:"clean", BuildDate:"2020-02-11T18:07:13Z", GoVersion:"go1.13.6", Compiler:"gc", Platform:"linux/amd64"}

我重新运行这些命令以将服务器部署到本地集群。有用!

不过,我无法在以下步骤中公开该服务。在 service.yaml 修改后,EXTERNAL-IP 永远不会出现。这是另一个问题。

于 2020-04-17T17:53:36.047 回答