簡體   English   中英

使用 C# 庫觀看 Kubernetes 事件

[英]Watch Kubernetes events using C# library

這是我第一次玩 K8s api/client。 我正在嘗試監視所有命名空間中的事件。 以下是方法,運行時打印:

例外:Object 引用未設置為 object 的實例。
關閉

關於如何使用C# 客戶端庫的文檔不足。 有人可以幫助我理解我做錯了什么嗎?

這是方法:

    public async Task Temp() {
        var config = KubernetesClientConfiguration.BuildConfigFromConfigFile();
        IKubernetes client = new Kubernetes(config);
        var resourceVersion = client.ListEventForAllNamespaces().ResourceVersion();
        var path = $"api/v1/events";
        // wait for events
        while (true)
        {
            var eventsWatcher = await client.WatchObjectAsync<V1EventList>(
            timeoutSeconds: int.MaxValue,
            path: path,
            resourceVersion: resourceVersion,
            onEvent: new Action<WatchEventType, V1EventList>((x, y) =>
            {
                Console.WriteLine(x.ToString());
            }),
            onClosed: new Action(() =>
            {
                Console.WriteLine("Closed");
            }),
            onError: new Action<Exception>((e) =>
            {
                Console.WriteLine($"Exception : {e.Message}");
            }));

        
            Thread.Sleep(1000);
        }
    }

附帶說明一下,我可以在 kubectl 代理之后使用 http://localhost:8080/api/v1/events?watch=1&resourceVersion=27958468 在本地觀看

發現問題。 我使用了錯誤的“路徑”。 而不是 api/v1/events 它應該是api/v1/watch/events NullReferenceException 發生在庫的watcher.cs 第 149 行

在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM