2

like local environment we first login to az account and the run two commands for connecting AKS .

just like that, how we can connect through runbook python script and manage resources like deleting pods, deployments ,services . I used below azure python sdk script.

from kubernetes import client, config
from kubernetes.client.rest import ApiException

# config.load_incluster_config()
# config.load_kube_config()

config.load_incluster_config()
configuration = client.Configuration()

with client.ApiClient(configuration) as api_client:
    api_instance = client.CoreV1Api(api_client)
  
    namespace = 'default' # str | see @Max Lobur's answer on how to get this
    name = 'PodName' # str | Pod name, e.g. via api_instance.list_namespaced_pod(namespace)
    
    try:
        api_response = api_instance.delete_namespaced_pod(name, namespace)
        print(api_response)
    except ApiException as e:
        print("Exception when calling CoreV1Api->delete_namespaced_pod: %s\n" % e)
---------------------------------------------------------------------------------------

out put of that
Failed
Traceback (most recent call last):  File "C:\Temp\trfoszt2.pnq\abb1bda8-2ca8-4a11-8ce9-d75a880004fa", line 237, in <module>    config.load_incluster_config()  File "C:\WPy64-3800\python-3.8.0.amd64\lib\site-packages\kubernetes\config\incluster_config.py", line 118, in load_incluster_config    InClusterConfigLoader(  File "C:\WPy64-3800\python-3.8.0.amd64\lib\site-packages\kubernetes\config\incluster_config.py", line 54, in load_and_set    self._load_config()  File "C:\WPy64-3800\python-3.8.0.amd64\lib\site-packages\kubernetes\config\incluster_config.py", line 62, in _load_config    raise ConfigException("Service host/port is not set.")kubernetes.config.config_exception.ConfigException: Service host/port is not set.
--------------------------------------------------------------------------------

I created runasaccount and in automation.
Jamiu S.
  • 5,257
  • 5
  • 12
  • 34

0 Answers0