I am working on a project in which I am using Python (3.6) and the Python container API client.
I need to do an automatic deployment in the container, I did with the creation of the cluster, but now the problem is the status of cluster provisioning. When the cluster was created by our code after this, the service was immediately deployed, but if I look at the GCP console, the cluster still provides why the deployment causes an error:
Getting Cluster Endpoint ...
WARNING: the cluster machine is not working. The Kubernet API may not be available.
ERROR: (gcloud.container.clusters.get-credentials) The cluster machine is missing an endpoint. Is it still PRELIMINARY?
Here is my code: From views.py:
# From here GCP stuff has been started auth = views.getauth() cluster_body = { "cluster": { "name": deployment.deploymentName.lower(), "description": 'A Cluster from IGui', "initialNodeCount": deployment.nodeSize, "enableKubernetesAlpha": True, "nodeConfig": { "machineType": 'n1-standard-2', "imageType": deployment.image }, } } service = discovery.build('container', 'v1beta1', http=auth, cache_discovery=False) cl = service.projects().zones().clusters() list_resp = cl.create(projectId=deployment.project, zone=deployment.region, body=cluster_body).execute() print(list_resp) # Prepare service to deploy: usrService = """ apiVersion: v1 kind: Service metadata: name: node-service labels: app: node spec: ports: - name: tcp port: 9080 selector: app: node --- apiVersion: extensions/v1beta1 kind: Deployment metadata: name: node-service spec: replicas: 1 template: metadata: labels: app: node spec: containers: - name: node image: image: arycloud/istio_dep:""" + tag + """ imagePullPolicy: IfNotPresent ports: - containerPort: 9080 --- ########################################################################### # Ingress resource (gateway) ########################################################################## apiVersion: extensions/v1beta1 kind: Ingress metadata: name: gateway annotations: kubernetes.io/ingress.class: "istio" spec: rules: - http: paths: - path: / backend: serviceName: node-service servicePort: 9080 --- """ saved_unmask = os.umask(0o077) istio_dir_path = os.path.join(IGui.settings.BASE_DIR, 'static', 'istio') print(istio_dir_path) # Create User service file usvc = tempfile.mkdtemp() path = os.path.join(usvc) print(path) try: with open(path + '/nodeService.yaml', "w") as nodeService: nodeService.write(usrService) except IOError as e: print('IOError:', e) finally: os.umask(saved_unmask) # Start deployment # Setup istio on cluster print('Fetching Cluster configs ....') cc = subprocess.call( 'gcloud container clusters get-credentials ' + deployment.deploymentName.lower() + ' --zone ' + deployment.region + ' --project ' + deployment.project, shell=True) print(cc) istio_auth = subprocess.call('kubectl apply -f https://github.com/istio/istio/blob/master/install/kubernetes/istio-auth.yaml') print(istio_auth) usrSvc_deployment = subprocess.call('kubectl apply -f ' + path + 'nodeService.yaml') print(usrSvc_deployment) return HttpResponse(deployment, status=200)
How can I get the proper cluster grant status through the API? and install my deployment, if the cluster was provided otherwise, will make the wait process.
Also: I process this request using ajax.
Help me please!
Thanks in advance!