TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Show HN: Kr8s – a Python client library for Kubernetes

139 点作者 jacobtomlinson超过 1 年前
Hey folks. I&#x27;m the author of kr8s.<p>I’ve been working on kr8s for a while now and one of my core goals is to build a Python library for Kubernetes that is the most simple, readable and produces the most maintainable code. It should enable folks to write clean code when working with the Kubernetes API.<p>If you&#x27;re interested in how it compares with other libraries then check out [this post](<a href="https:&#x2F;&#x2F;jacobtomlinson.dev&#x2F;posts&#x2F;2023&#x2F;comparison-of-kr8s-vs-other-python-libraries-for-kubernetes&#x2F;" rel="nofollow noreferrer">https:&#x2F;&#x2F;jacobtomlinson.dev&#x2F;posts&#x2F;2023&#x2F;comparison-of-kr8s-vs-...</a>).<p>Happy to answer any questions you might have in the comments here .

18 条评论

multani超过 1 年前
This looks really cool!<p>I wrote a few applications using both the official Kubernetes client and the asyncio variant from Tomasz. Both have the same problems to me (that you exposed on the comparison page):<p>The documentation is really terrible (it&#x27;s even non-existent for kubernetes-asyncio). For the official client, it&#x27;s hidden deep inside the repository, across <i>hundreds</i> of files (592 at the moment); half the link cross doc don&#x27;t work, there are rendering issues, etc. It&#x27;s really a gigantic mess.<p>The API is extremely verbose, directly the underlying Kubernetes API exposed to Python. It gets the job done and it&#x27;s better than shell script, but the verbosity + the total lack of a decent documentation (cf. above) makes it hard to use and see what you can do with it. Most of the time, you have to fire the REPL and try a bunch of calls until it makes sense. I like that most of the responses are proper objects, but they display as dict in the REPL and of course, the responses format are not documented in the doc :)<p>Last but not least: they both lack support for fancy authentication mechanism. We go to Kubernetes through a fancy proxy that require specific TLS settings + an external exec plugin to get the credentials. The official Kubernetes client should have the right support (for what we need at least) in the next major version but the asyncio variant not yet (I made a PR to fix this, but this requires a new version of aiohttp which is not released yet...) Both clients are very similar for the autogenerated code, but also subtly different for all the things around so you can&#x27;t really expect 100% that what works on one will work on the other.<p>I&#x27;m not sure how kr8s works with this fancy auth system, but at least for the first 2 points, it seems like a huge win, I&#x27;ll give it a try!
评论 #37502525 未加载
评论 #37505146 未加载
theptip超过 1 年前
In the past I used PyKube (<a href="https:&#x2F;&#x2F;pykube.readthedocs.io&#x2F;en&#x2F;latest&#x2F;readme.html" rel="nofollow noreferrer">https:&#x2F;&#x2F;pykube.readthedocs.io&#x2F;en&#x2F;latest&#x2F;readme.html</a>), which did the job. One issue that pykube has is that there is no autocomplete on API object fields. Does kr8s wire this up? Seems you could use a TypedDict on newer versions of Python.<p>Back in the old days you wouldn&#x27;t get autocomplete on k8s YAML files either, but now the schema is well-known and so your IDE will complete all the fields (even CRDs). These days you get this with Pulumi, if I&#x27;m not mistaken.
评论 #37501967 未加载
Nullabillity超过 1 年前
Requesting objects without a specific version&#x2F;apigroup is pretty dangerous, you&#x27;re effectively opting out of K8s&#x27; primary backwards compatibility measure.
snug超过 1 年前
Looks great, but I&#x27;m bashing my head trying to figure out what the r means in kr8s?
评论 #37506439 未加载
评论 #37505372 未加载
nyellin超过 1 年前
To put one more option out there, we use Hikaru (<a href="https:&#x2F;&#x2F;pypi.org&#x2F;project&#x2F;hikaru&#x2F;" rel="nofollow noreferrer">https:&#x2F;&#x2F;pypi.org&#x2F;project&#x2F;hikaru&#x2F;</a>) in Robusta.dev (<a href="https:&#x2F;&#x2F;github.com&#x2F;robusta-dev&#x2F;robusta">https:&#x2F;&#x2F;github.com&#x2F;robusta-dev&#x2F;robusta</a>) and have been pretty happy with it. Example code below:<p><pre><code> with Pod().read(name=&#x27;thename&#x27;, namespace=&#x27;the-namespace&#x27;) as p: p.labels[&#x27;new-label&#x27;] = &#x27;value&#x27;</code></pre>
评论 #37506429 未加载
cpressland超过 1 年前
I have literally just spent the last few weeks writing pydantic models for Kubernetes for an internal testing tool. I’ll see how this compares, it looks outstanding.
评论 #37502567 未加载
uneekname超过 1 年前
This is awesome. Jacob, your work on Dask Kubernetes has been immensely helpful to me. The world of distributed Python grows stronger!
评论 #37502590 未加载
willthames超过 1 年前
The comparison doesn’t include the (perhaps confusingly named) openshift library. All the ansible kubernetes modules rely heavily on it because its support for dynamic client (where you just want to apply a manifest and don’t know in advance that it’s a Deployment and a Service and a ConfigMap) is first rate.
评论 #37502745 未加载
techdragon超过 1 年前
I used this in my KiwiPyCon conference talk yesterday! I used it with Kopf to write a basic little kubernetes operator in Python.<p>Wish I had seen this thread before my talk, but the YouTube video will be online soon and I can link to it when they are uploaded.
kungfufrog超过 1 年前
This looks great, will be giving it a go today to replace some increasingly complex bash scripts!
评论 #37501502 未加载
评论 #37501443 未加载
aknfxb3m超过 1 年前
I stopped at the 3rd example. Kr8s and lightkube are the only solutions I&#x27;d dare to use.
评论 #37502561 未加载
bovermyer超过 1 年前
This is delightful. I&#x27;ll be taking it for a spin today.
评论 #37507249 未加载
dbragdon超过 1 年前
Awesome library, but I can&#x27;t view the documentation at work since the doc site uses http. Please consider using https.
评论 #37501432 未加载
评论 #37501377 未加载
ledauphin超过 1 年前
does this provide sane default behavior for refreshing expired auth tokens and retrying random client timeouts? the &quot;official&quot; SDK has driven me absolutely crazy trying to wrap all the different pieces with retries so that basic long-running operations won&#x27;t randomly raise spurious exceptions...
评论 #37507257 未加载
bjt12345超过 1 年前
How do you connect remotely? The examples don&#x27;t easily show this.
评论 #37502510 未加载
bdcravens超过 1 年前
Seems to be a verbal namespace collision with Rust crates (assuming it&#x27;s pronounced the same)
评论 #37507219 未加载
评论 #37505379 未加载
codetrotter超过 1 年前
How do you pronounce it?<p>Krewbernetes?<p>Krates?
评论 #37505377 未加载
gustavus超过 1 年前
The cycle of tooling<p>Step 1: Look I&#x27;ve made this new great tool that uses a declarative language, you simply declare what you want your environment to look like and boom it will build it out. No more having to figure out a complicated logic flows that can fail or having code that dies on weird error cases, and you don&#x27;t have to be a developer to use it.<p>Step 2: The tool isn&#x27;t powerful or flexible enough and the declarative code is getting to cumbersome so we&#x27;ve introduced some basic templating and logic flow to this tool to make it more flexible and reduce bloat.<p>Step 3: The control flow isn&#x27;t powerful enough to really meet our needs so we have moved it entirely to a full programming language.<p>Step 4: Go back to step 1.
评论 #37502615 未加载
评论 #37502521 未加载
评论 #37502766 未加载