0

Following Ryan Baxter's Spring On Kubernetes workshop, I run into a problem I can't resolve. On the step of "Deploying To Kubernetes", after generating depoyment.yaml and services.yaml files, I run

kubectl apply -f ./k8s

and I get validation errors:

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 

After running

kubectl apply -f ./k8s --validate=false

I get

error: unable to recognize "k8s/deployment.yaml": no matches for extensions/, Kind=Deployment
service"my-app" created

And here is the yaml file:

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: {}

Based on Harsh's suggestion, I change the apiVersion to apps/v1 and run the kubectl apply command again.

deployment "my-app" created
service "my-app" configured    

Based on what is shown in the watch, I run

kubectl port-forward svc/my-app 8080:80 

where svc/my-app is shown in the watch. And it yields

error: invalid resource name svc/my-app: [may not contain '/']       

To clean up, I run

kubectl delete -f ./k8s

And it yields

service "my-app" deleted
Error from server (NotFound): error when stopping "k8s/deployment.yaml": the server could not find the requested resource

I don't know whether those problems are caused by my operations errors or some bugs.

vic
  • 2,548
  • 9
  • 44
  • 74
  • can you please check the version of kubernetes you are running ? or else please run it like `kubectl apply -f ./k8s --validate=false` – Harsh Manvar Apr 17 '20 at 04:59
  • 1
    Thanks. That reminds me that I do see a version difference warning. I didn't recognize that it could be the cause. – vic Apr 17 '20 at 05:32
  • Regarding the "invalid resource name" error, I think your kubectl version is too old. – Chanseok Oh Apr 17 '20 at 14:41
  • Thanks for your information. It is one version older. I resolve the problem with an update. – vic Apr 17 '20 at 17:36

2 Answers2

0

save this and deploy this file : 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: {}
Harsh Manvar
  • 27,020
  • 6
  • 48
  • 102
  • Thanks very much again for your input. I have different access on Docker host so I use Docker Hub. Based on your information, I make a change in the development yaml file (see the updated question). There are still some problems. – vic Apr 17 '20 at 06:42
  • once you appiled YAML file after that checked POD status ? Running or crashing ? – Harsh Manvar Apr 17 '20 at 06:46
  • 1
    After I upgrade gcloud components, kubectl apply -f ./r-k8s --validate=false Error from server (NotFound): error when creating "r-k8s/service.yaml": the server could not find the requested resource unable to recognize "r-k8s/deployment.yaml": no matches for kind "Deployment" in version "" But my yaml files are ok. – vic Apr 17 '20 at 17:39
0

With help from Harsh and Chanseok, I upgrade gcloud components which kubectl is one of those components.

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"}

I rerun those commands to deploy the server to the local cluster. It works!

I can't expose the service in the following step, though. An EXTERNAL-IP never shows up after the service.yaml modification. It is another problem.

vic
  • 2,548
  • 9
  • 44
  • 74
  • The guide you used said "NOTE: `LoadBalancer` features are platform specific. The visibility of your app after changing the service type might depend a lot on where it is deployed (e.g. per cloud provider)." This is indeed true. Based on what you said, I believe you are using GKE (Google Cloud). In many cases, you don't have to expose/assign a public IP of a production cluster. Often you'll use other ways of controlling load balancing and ingress. See https://cloud.google.com/kubernetes-engine/docs/how-to/exposing-apps and https://cloud.google.com/kubernetes-engine/docs/tutorials/http-balancer – Chanseok Oh Apr 17 '20 at 21:02
  • @Chanseok Thanks for your input. what I have so far is a local cluster. So, I think the server needs to have an external IP address. – vic Apr 17 '20 at 22:18
  • Local clusters don't and can't have an external IP. – Chanseok Oh Apr 18 '20 at 00:15