简体   繁体   中英

ConfingExeption while Sending a job signal to kubernetes inside django to activate a pod

I have made a C++ program and set it up with docker/kubernetes inside google cloud using Github actions. I have 3 active pods inside my cluster and my c++ program basically takes a json as an input from a django application and gives an output. My goal right now is to trigger a pod inside django. Right now i wrote some code using the official kubernetes django package but I'm getting an error:

Here is what i wrote up until now:

from kubernetes import client, config, utils
import kubernetes.client
from kubernetes.client.rest import ApiException

# Set logging
logging.basicConfig(stream=sys.stdout, level=logging.INFO)

# Setup K8 configs
# config.load_incluster_config("./kube-config.yaml")
config.load_kube_config("./kube-config.yaml")
configuration = kubernetes.client.Configuration()
api_instance = kubernetes.client.BatchV1Api(kubernetes.client.ApiClient(configuration))

I don't know much about the kube-config.yaml file so i borrowed a code from the internet:

apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: test
spec:
  schedule: "*/5 * * * *"
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: test
            image: test:v5
            env:
            imagePullPolicy: IfNotPresent
            command: ['./CppProgram']
            args: ['project.json']
          restartPolicy: OnFailure

The yaml file and the python file are in the same directory.

But when i call this via a view i get this error on the console:

kubernetes.config.config_exception.ConfigException: Invalid kube-config file. No configuration found.

Is my load_kube_config call at fault or is my yaml file wrong? If so is there an example i can look into?

I saw this question asked before, I think according to here I should use load_kube_config (I've already deployed to google kubernetes engine and the pods should be ready. ) but I'm not sure.

You need to use load_incluster_config() function instead of load_kube_config().

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM