apiVersion: batch/v1 kind: Job metadata: name: test-iris-inference namespace: kserve spec: template: spec: containers: - name: test image: python:3.9-slim command: - /bin/sh - -c - | cat << 'EOF' | python import urllib.request import json # KServe endpoint (v2 protocol) url = "http://iris-classifier-predictor.kserve.svc.cluster.local/v2/models/iris-classifier/infer" # Iris class names class_names = ["setosa", "versicolor", "virginica"] # Test samples with expected results test_cases = [ {"data": [5.1, 3.5, 1.4, 0.2], "expected": "setosa"}, {"data": [6.7, 3.0, 5.2, 2.3], "expected": "virginica"}, {"data": [5.9, 3.0, 4.2, 1.5], "expected": "versicolor"}, ] print("=" * 60) print("Testing Iris Classifier InferenceService") print("=" * 60) print(f"Endpoint: {url}") print() for i, test_case in enumerate(test_cases, 1): print(f"Test Case {i}:") print(f" Input: {test_case['data']}") print(f" Expected: {test_case['expected']}") # v2 protocol payload payload = { "inputs": [ { "name": "input-0", "shape": [1, 4], "datatype": "FP64", "data": [test_case['data']] } ] } try: req = urllib.request.Request( url, data=json.dumps(payload).encode('utf-8'), headers={'Content-Type': 'application/json'} ) with urllib.request.urlopen(req) as response: result = json.loads(response.read().decode('utf-8')) prediction = result['outputs'][0]['data'][0] predicted_class = class_names[prediction] status = "✓ PASS" if predicted_class == test_case['expected'] else "✗ FAIL" print(f" Predicted: {predicted_class} (class {prediction})") print(f" Status: {status}") except Exception as e: print(f" Error: {e}") print() print("=" * 60) print("Test completed") print("=" * 60) EOF restartPolicy: Never backoffLimit: 1 --- # Alternative: curl-based quick test # apiVersion: batch/v1 # kind: Job # metadata: # name: test-iris-inference-curl # namespace: kserve # spec: # template: # spec: # containers: # - name: test # image: curlimages/curl:latest # command: # - /bin/sh # - -c # - | # echo "Testing Iris Classifier Inference Service..." # echo "" # echo "Endpoint: http://iris-classifier-predictor.kserve.svc.cluster.local/v2/models/iris-classifier/infer" # echo "" # echo "Sending test request with sample data: [5.1, 3.5, 1.4, 0.2]" # echo "Expected prediction: class 0 (setosa)" # echo "" # # curl -v -X POST \ # http://iris-classifier-predictor.kserve.svc.cluster.local/v2/models/iris-classifier/infer \ # -H "Content-Type: application/json" \ # -d '{ # "inputs": [ # { # "name": "input-0", # "shape": [1, 4], # "datatype": "FP64", # "data": [[5.1, 3.5, 1.4, 0.2]] # } # ] # }' # # echo "" # echo "" # echo "Testing with multiple samples..." # echo "" # # curl -X POST \ # http://iris-classifier-predictor.kserve.svc.cluster.local/v2/models/iris-classifier/infer \ # -H "Content-Type: application/json" \ # -d '{ # "inputs": [ # { # "name": "input-0", # "shape": [3, 4], # "datatype": "FP64", # "data": [ # [5.1, 3.5, 1.4, 0.2], # [6.7, 3.0, 5.2, 2.3], # [5.9, 3.0, 4.2, 1.5] # ] # } # ] # }' # # echo "" # restartPolicy: Never # backoffLimit: 1