gkv
gkv

Reputation: 344

Create an Istio Virtual Service with K8s Python API?

I'm building a Kubernetes application that Dockerizes code and runs it on the cluster. In order for users to be able to invoke their Dockerized code, I need to modify the Istio configuration to expose the service they've created.

I'm trying to create Istio virtual services using the Python API. I'm able to list existing Istio resources:

group = 'networking.istio.io' 
version = 'v1alpha3' 
plural = 'destinationrules' 

from kubernetes import client, config
config.load_kube_config()

myclient = client.CustomObjectsApi()
api_response = myclient.list_cluster_custom_object(group, version, plural)

but when I use the same parameters to create, I get a 404 not found error.

with open('destination-rule.yaml', 'r') as file_reader:
    file_content = file_reader.read()

deployment_template = yaml.safe_load(file_content)

api_response = myclient.create_cluster_custom_object(
   group=group, version=version, plural=plural, body=body)

The destination-rule.yaml file looks like:

apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
  name: test
spec:
  host: test
  subsets:
  - name: v1
    labels:
      run: test

What am I doing wrong here?

Upvotes: 0

Views: 767

Answers (1)

gkv
gkv

Reputation: 344

My problem was that I was doing create_cluster_custom_object instead of create_namespaced_custom_object. When I switched over, it started working.

Upvotes: 1

Related Questions