从内部pod创建kubectl [英] kubectl create from inside pod

查看:330
本文介绍了从内部pod创建kubectl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个正在运行的詹金斯(Jenkins)吊舱,我正在尝试执行以下命令:

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

出现以下错误:

服务器错误(未找到):服务器找不到请求的资源

这是哪里出问题了?

ab-back.yml文件

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

更新:

kubectl version如下:

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

在将日志用作--v=4时,kubectl apply正在工作并提供日志,如下所示:

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

但是kubectl create给出错误消息:

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

也在执行kubectl get pods --v=10时,它给出的日志为:

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

推荐答案

问题出在版本中,请尝试使用客户端的旧版本或升级服务器. kubectl支持一种版本的向前和向后倾斜:

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:

来自

一个客户端的偏移量不应超过该版本的一个次要版本. 大师,但最多可以领导一个次要版本.为了 例如,一个v1.3主节点应与v1.1,v1.2和v1.3节点一起使用, 并应与v1.2,v1.3和v1.4客户端一起使用.

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.

这篇关于从内部pod创建kubectl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆