0

I have written a C++ program and set it up with docker/kubernetes hosted on Google Cloud using Github actions.

I have 3 active pods within my cluster and my c++ program basically takes a json as the input from a Django application and produces an output.

My current goal is to trigger a pod from django.

Right now I have written some code using the official Kubernetes Django package but I'm getting an error:

Here is what I have developed 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 have borrowed one 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 approach wrong 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 have used load_kube_config (I've already deployed to google kubernetes engine and the pods should be ready. ) but I'm not sure.

london_utku
  • 1,070
  • 2
  • 16
  • 36
Turgut
  • 711
  • 3
  • 25

1 Answers1

0

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

london_utku
  • 1,070
  • 2
  • 16
  • 36