kubectl create from inside pod

7/2/2018

I have a running jenkins pod and i am trying to execute following commands:

sudo kubectl --kubeconfig /opt/jenkins_home/admin.conf apply -f /opt/jenkins_home/ab-kubernetes/ab-back.yml

It is giving following error:

Error from server (NotFound): the server could not find the requested resource

What cound go wrong here?

ab-back.yml file

---
apiVersion: v1
kind: Service
metadata:
  name: dg-back-svc
spec:
  selector:
    app: dg-core-backend-d
  type: NodePort
  ports:
    - name: http
      protocol: TCP
      port: 8081
      nodePort: 30003
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: dg-core-backend-d
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: dg-core-backend-d
    spec:
      containers:
      - name: dg-core-java
        image: ab/dg-springboot-java:1.0
        imagePullPolicy: IfNotPresent
        command: ["sh"]
        args: ["-c", "/root/post-deployment.sh"]
        ports:
        - containerPort: 8081
        # livenessProbe:
        #   httpGet:
        #     path: /
        #     port: 8080
        env:
        - name: SPRING_PROFILES_ACTIVE
          value: xxx

UPDATE:

kubectl version is as follows :

Client Version: version.Info{Major:"1", Minor:"11", GitVersion:"v1.11.0", GitCommit:"91e7b4fd31fcd3d5f436da26c980becec37ceefe", GitTreeState:"clean", BuildDate:"2018-06-27T20:17:28Z", GoVersion:"go1.10.2", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"6", GitVersion:"v1.6.0", GitCommit:"fff5156092b56e6bd60fff75aad4dc9de6b6ef37", GitTreeState:"clean", BuildDate:"2017-03-28T16:24:30Z", GoVersion:"go1.7.5", Compiler:"gc", Platform:"linux/amd64"}

On applying logs as --v=4,kubectl apply is working and giving logs as follows :

I0702 11:40:17.721604    1601 merged_client_builder.go:159] Using in-cluster namespace
I0702 11:40:17.734648    1601 decoder.go:224] decoding stream as YAML
service/dg-back-svc created
deployment.extensions/dg-core-backend-d created

but kubectl create is giving error as :

I0702 11:41:12.265490    1631 helpers.go:201] server response object: [{
  "metadata": {},
  "status": "Failure",
  "message": "the server could not find the requested resource",
  "reason": "NotFound",
  "details": {
    "causes": [
      {
        "reason": "UnexpectedServerResponse",
        "message": "unknown"
      }
    ]
  },
  "code": 404
}]

Also on doing kubectl get pods --v=10,it is giving log as :

Response Body: {
  "metadata": {},
  "status": "Failure",
  "message": "only the following media types are accepted: application/json, application/yaml, application/vnd.kubernetes.protobuf",
  "reason": "NotAcceptable",
  "code": 406
}
I0702 12:34:27.542564    2514 request.go:1099] body was not decodable (unable to check for Status): Object 'Kind' is missing in '{
  "metadata": {},
  "status": "Failure",
  "message": "only the following media types are accepted: application/json, application/yaml, application/vnd.kubernetes.protobuf",
  "reason": "NotAcceptable",
  "code": 406
}'
No resources found.
I0702 12:34:27.542813    2514 helpers.go:201] server response object: [{
  "metadata": {},
  "status": "Failure",
  "message": "unknown (get pods)",
  "reason": "NotAcceptable",
  "details": {
    "kind": "pods",
    "causes": [
      {
        "reason": "UnexpectedServerResponse",
        "message": "unknown"
      }
    ]
  },
  "code": 406
}]
-- Utkarsh Saraf
docker
jenkins
kubernetes

2 Answers

7/2/2018

Kubernetes server doesnt have this extensions/v1beta1 this resources. thats the reason why you cannot create dg-core-backend-d You can check this by typing kubectl api-versions

-- Dinesh
Source: StackOverflow

7/2/2018

The problem is in versions, try to use the old version of the client or upgrade the server. kubectl supports one version forward and backward skew:

From documentation

a client should be skewed no more than one minor version from the master, but may lead the master by up to one minor version. For example, a v1.3 master should work with v1.1, v1.2, and v1.3 nodes, and should work with v1.2, v1.3, and v1.4 clients.

-- Nick Rak
Source: StackOverflow