Django kubernetes connection Max retries exceeded with url

Я пытаюсь создать kubernetes job внутри google cloud с помощью django и когда я вызываю мое представление rest_api, я получаю эту ошибку:

ConnectionRefusedError: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPConnection object at 
0x7fc745e58580>: Failed to establish a new connection: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=80): Max retries exceeded with url: /apis/batch/v1/ 
(Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fc745e58580>: Failed to establish a new connection: [Errno 111] Connection refused'))

Вот мой kubec-config.yaml:

apiVersion: v1
kind: Config
clusters:
- cluster:
    certificate-authority-data: DATA+OMITTED
    server: ---
  name: gke_---_europe-west1_cluster-1
users:
- name: cluster-1
current-context: gke_---_europe-west1_cluster-1
contexts:
- context:
    cluster: gke_---_europe-west1_cluster-1
    user: gke_---_europe-west1_cluster-1
  name: gke_---_europe-west1_cluster-1

spec:
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: cluster-1
            image: cluster-1:v5
            env:
            imagePullPolicy: IfNotPresent
            command: ['./Renderer']
            args: ['project.json']
          restartPolicy: OnFailure

Я получил много информации здесь, запустив kubectl config view в облаке Google и просто скопировал и вставил их сюда.

А это мой APIview:

class ProjectExportView(APIView):
    def get(self, request, uuid):
        jobs = ["", "", ""]
        try:
            project = Project.objects.get(uuid=uuid)
            from utils.gke import kube_test_credentials, kube_cleanup_finished_jobs, kube_delete_empty_pods, kube_create_job
            import os

            # Testing Credentials
            kube_test_credentials()
            # We try to cleanup dead jobs (READ THE FUNCTION CODE!)
            kube_cleanup_finished_jobs()
            kube_delete_empty_pods()
            # Create a couple of jobs
            for i in range(3):
                jobs[i] = kube_create_job(project.manifest)
            # This was to test the use of ENV variables.
            logging.info("Finshed! - ENV: {}".format(os.environ["VAR"]))

        except:
            logging.info("ProjectExportView failed for thumbnail for the project uuid : {uuid}")
            exception_message = traceback.format_exc()
            logging.info(f"Exception message : {exception_message}")

        return Response(
                    {
                        "uuid"      : uuid,
                        "Job1"      : jobs[0],
                        "Job2"      : jobs[1],
                        "Job3"      : jobs[2],
                    }
                )

Возможно, я получаю ошибку kube_test_credentials(), которая выглядит следующим образом:

...
with open("utils/kube-config.yaml", "r", encoding="utf-8") as file:
    config.load_kube_config(file)
# Setup K8 configs
configuration = kubernetes.client.Configuration()
api_instance = kubernetes.client.BatchV1Api(kubernetes.client.ApiClient(configuration))
...
def kube_test_credentials():
    try: 
        api_response = api_instance.get_api_resources()
        logging.info(api_response)
    except ApiException as e:
        print("Exception when calling API: %s\n" % e)

Как раз для проверки проблем с подключением. В чем здесь может быть проблема? Должен ли я поместить информацию об учетной записи службы в файл kubec-config.yaml? Если да, то как мне это сделать?

Вернуться на верх