mirror of
https://github.com/rancher/rancher-docs.git
synced 2026-09-27 21:50:21 +00:00
30 lines
33 KiB
HTML
30 lines
33 KiB
HTML
<!doctype html>
|
||
<html lang="zh" dir="ltr" class="docs-wrapper docs-doc-page docs-version-2.7 plugin-docs plugin-id-default docs-doc-id-reference-guides/about-the-api/about-the-api" data-has-hydrated="false">
|
||
<head>
|
||
<meta charset="UTF-8">
|
||
<meta name="generator" content="Docusaurus v2.4.3">
|
||
<title data-rh="true">API | Rancher</title><meta data-rh="true" name="viewport" content="width=device-width,initial-scale=1"><meta data-rh="true" name="twitter:card" content="summary_large_image"><meta data-rh="true" property="og:url" content="https://ranchermanager.docs.rancher.com/zh/v2.7/reference-guides/about-the-api"><meta data-rh="true" name="docusaurus_locale" content="zh"><meta data-rh="true" name="docsearch:language" content="zh"><meta data-rh="true" name="docusaurus_version" content="2.7"><meta data-rh="true" name="docusaurus_tag" content="docs-default-2.7"><meta data-rh="true" name="docsearch:version" content="2.7"><meta data-rh="true" name="docsearch:docusaurus_tag" content="docs-default-2.7"><meta data-rh="true" property="og:title" content="API | Rancher"><meta data-rh="true" name="description" content="如何使用 API"><meta data-rh="true" property="og:description" content="如何使用 API"><link data-rh="true" rel="icon" href="/zh/img/favicon.png"><link data-rh="true" rel="alternate" href="https://ranchermanager.docs.rancher.com/v2.7/reference-guides/about-the-api" hreflang="en"><link data-rh="true" rel="alternate" href="https://ranchermanager.docs.rancher.com/zh/v2.7/reference-guides/about-the-api" hreflang="zh"><link data-rh="true" rel="alternate" href="https://ranchermanager.docs.rancher.com/v2.7/reference-guides/about-the-api" hreflang="x-default"><link data-rh="true" rel="preconnect" href="https://30NEY6C9UY-dsn.algolia.net" crossorigin="anonymous"><link data-rh="true" rel="canonical" href="https://ranchermanager.docs.rancher.com/zh/reference-guides/about-the-api"><link rel="preconnect" href="https://www.googletagmanager.com">
|
||
<script>window.dataLayer=window.dataLayer||[]</script>
|
||
<script>!function(e,t,a,n,g){e[n]=e[n]||[],e[n].push({"gtm.start":(new Date).getTime(),event:"gtm.js"});var m=t.getElementsByTagName(a)[0],r=t.createElement(a);r.async=!0,r.src="https://www.googletagmanager.com/gtm.js?id=GTM-57KS2MW",m.parentNode.insertBefore(r,m)}(window,document,"script","dataLayer")</script>
|
||
|
||
|
||
|
||
<link rel="search" type="application/opensearchdescription+xml" title="Rancher" href="/zh/opensearch.xml">
|
||
|
||
|
||
|
||
<script src="https://cdn.cookielaw.org/scripttemplates/otSDKStub.js" charset="UTF-8" data-domain-script="0f98beb0-fc4c-417d-a42e-564e2cae42d2" async></script>
|
||
<script src="/scripts/optanonwrapper.js" async></script><link rel="stylesheet" href="/zh/assets/css/styles.29ec6351.css">
|
||
<link rel="preload" href="/zh/assets/js/runtime~main.7955d3d3.js" as="script">
|
||
<link rel="preload" href="/zh/assets/js/main.129d8862.js" as="script">
|
||
</head>
|
||
<body class="navigation-with-keyboard">
|
||
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-57KS2MW" height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
|
||
|
||
|
||
<script>!function(){function t(t){document.documentElement.setAttribute("data-theme",t)}var e=function(){var t=null;try{t=new URLSearchParams(window.location.search).get("docusaurus-theme")}catch(t){}return t}()||function(){var t=null;try{t=localStorage.getItem("theme")}catch(t){}return t}();t(null!==e?e:"light")}()</script><div id="__docusaurus">
|
||
<div role="region" aria-label="跳到主要内容"><a class="skipToContent_fXgn" href="#__docusaurus_skipToContent_fallback">跳到主要内容</a></div><nav aria-label="主导航" class="navbar navbar--fixed-top"><div class="navbar__inner"><div class="navbar__items"><button aria-label="切换导航栏" aria-expanded="false" class="navbar__toggle clean-btn" type="button"><svg width="30" height="30" viewBox="0 0 30 30" aria-hidden="true"><path stroke="currentColor" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2" d="M4 7h22M4 15h22M4 23h22"></path></svg></button><a class="navbar__brand" href="/zh/"><div class="navbar__logo"><img src="/zh/img/rancher-logo-horiz-color.svg" alt="logo" class="themedImage_ToTc themedImage--light_HNdA"><img src="/zh/img/rancher-logo-horiz-color.svg" alt="logo" class="themedImage_ToTc themedImage--dark_i4oU"></div><b class="navbar__title text--truncate"></b></a><div class="navbar__item dropdown dropdown--hoverable"><a aria-current="page" class="navbar__link active" aria-haspopup="true" aria-expanded="false" role="button" href="/zh/v2.7">v2.7</a><ul class="dropdown__menu"><li><a class="dropdown__link" href="/zh/">Latest</a></li><li><a class="dropdown__link" href="/zh/v2.9">v2.9 (Preview)</a></li><li><a class="dropdown__link" href="/zh/v2.8">v2.8</a></li><li><a aria-current="page" class="dropdown__link dropdown__link--active" href="/zh/v2.7/reference-guides/about-the-api">v2.7</a></li><li><a class="dropdown__link" href="/zh/v2.6/reference-guides/about-the-api">v2.6</a></li><li><a class="dropdown__link" href="/zh/v2.5/reference-guides/about-the-api">v2.5</a></li><li><a class="dropdown__link" href="/zh/v2.0-v2.4/reference-guides/about-the-api">v2.0-v2.4</a></li><li><a class="dropdown__link" href="/zh/versions">All versions</a></li></ul></div><div class="navbar__item dropdown dropdown--hoverable"><a href="#" aria-haspopup="true" aria-expanded="false" role="button" class="navbar__link"><svg viewBox="0 0 24 24" width="20" height="20" aria-hidden="true" class="iconLanguage_nlXk"><path fill="currentColor" d="M12.87 15.07l-2.54-2.51.03-.03c1.74-1.94 2.98-4.17 3.71-6.53H17V4h-7V2H8v2H1v1.99h11.17C11.5 7.92 10.44 9.75 9 11.35 8.07 10.32 7.3 9.19 6.69 8h-2c.73 1.63 1.73 3.17 2.98 4.56l-5.09 5.02L4 19l5-5 3.11 3.11.76-2.04zM18.5 10h-2L12 22h2l1.12-3h4.75L21 22h2l-4.5-12zm-2.62 7l1.62-4.33L19.12 17h-3.24z"></path></svg>简体中文</a><ul class="dropdown__menu"><li><a href="/v2.7/reference-guides/about-the-api" target="_self" rel="noopener noreferrer" class="dropdown__link" lang="en">English</a></li><li><a href="/zh/v2.7/reference-guides/about-the-api" target="_self" rel="noopener noreferrer" class="dropdown__link dropdown__link--active" lang="zh">简体中文</a></li></ul></div><div class="searchBox_ZlJk"><button type="button" class="DocSearch DocSearch-Button" aria-label="搜索"><span class="DocSearch-Button-Container"><svg width="20" height="20" class="DocSearch-Search-Icon" viewBox="0 0 20 20"><path d="M14.386 14.386l4.0877 4.0877-4.0877-4.0877c-2.9418 2.9419-7.7115 2.9419-10.6533 0-2.9419-2.9418-2.9419-7.7115 0-10.6533 2.9418-2.9419 7.7115-2.9419 10.6533 0 2.9419 2.9418 2.9419 7.7115 0 10.6533z" stroke="currentColor" fill="none" fill-rule="evenodd" stroke-linecap="round" stroke-linejoin="round"></path></svg><span class="DocSearch-Button-Placeholder">搜索</span></span><span class="DocSearch-Button-Keys"></span></button></div></div><div class="navbar__items navbar__items--right"><div class="navbar__item dropdown dropdown--hoverable dropdown--right"><a href="#" aria-haspopup="true" aria-expanded="false" role="button" class="navbar__link">Quick Links</a><ul class="dropdown__menu"><li><a href="https://github.com/rancher/rancher" target="_blank" rel="noopener noreferrer" class="dropdown__link">GitHub<svg width="12" height="12" aria-hidden="true" viewBox="0 0 24 24" class="iconExternalLink_nPIU"><path fill="currentColor" d="M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z"></path></svg></a></li><li><a href="https://github.com/rancher/rancher-docs" target="_blank" rel="noopener noreferrer" class="dropdown__link">Docs GitHub<svg width="12" height="12" aria-hidden="true" viewBox="0 0 24 24" class="iconExternalLink_nPIU"><path fill="currentColor" d="M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z"></path></svg></a></li></ul></div><div class="navbar__item dropdown dropdown--hoverable dropdown--right"><a href="#" aria-haspopup="true" aria-expanded="false" role="button" class="navbar__link">More from SUSE</a><ul class="dropdown__menu"><li><a href="https://www.rancher.com" target="_blank" rel="noopener noreferrer" class="dropdown__link navbar__icon navbar__rancher">Rancher<svg width="12" height="12" aria-hidden="true" viewBox="0 0 24 24" class="iconExternalLink_nPIU"><path fill="currentColor" d="M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z"></path></svg></a></li><li><hr style="margin: 0.3rem 0;"></li><li><a href="https://elemental.docs.rancher.com/" target="_blank" rel="noopener noreferrer" class="dropdown__link navbar__icon navbar__elemental">Elemental<svg width="12" height="12" aria-hidden="true" viewBox="0 0 24 24" class="iconExternalLink_nPIU"><path fill="currentColor" d="M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z"></path></svg></a></li><li><a href="https://fleet.rancher.io/" target="_blank" rel="noopener noreferrer" class="dropdown__link navbar__icon navbar__fleet">Fleet<svg width="12" height="12" aria-hidden="true" viewBox="0 0 24 24" class="iconExternalLink_nPIU"><path fill="currentColor" d="M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z"></path></svg></a></li><li><a href="https://harvesterhci.io" target="_blank" rel="noopener noreferrer" class="dropdown__link navbar__icon navbar__harvester">Harvester<svg width="12" height="12" aria-hidden="true" viewBox="0 0 24 24" class="iconExternalLink_nPIU"><path fill="currentColor" d="M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z"></path></svg></a></li><li><a href="https://rancherdesktop.io/" target="_blank" rel="noopener noreferrer" class="dropdown__link navbar__icon navbar__rancher__desktop">Rancher Desktop<svg width="12" height="12" aria-hidden="true" viewBox="0 0 24 24" class="iconExternalLink_nPIU"><path fill="currentColor" d="M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z"></path></svg></a></li><li><hr style="margin: 0.3rem 0;"></li><li><a href="https://opensource.suse.com" target="_blank" rel="noopener noreferrer" class="dropdown__link navbar__icon navbar__suse">More Projects...<svg width="12" height="12" aria-hidden="true" viewBox="0 0 24 24" class="iconExternalLink_nPIU"><path fill="currentColor" d="M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z"></path></svg></a></li></ul></div></div></div><div role="presentation" class="navbar-sidebar__backdrop"></div></nav><div id="__docusaurus_skipToContent_fallback" class="main-wrapper mainWrapper_z2l0 docsWrapper_BCFX"><button aria-label="回到顶部" class="clean-btn theme-back-to-top-button backToTopButton_sjWU" type="button"></button><div class="docPage__5DB"><aside class="theme-doc-sidebar-container docSidebarContainer_b6E3"><div class="sidebarViewport_Xe31"><div class="sidebar_njMd"><nav aria-label="文档侧边栏" class="menu thin-scrollbar menu_SIkG"><ul class="theme-doc-sidebar-menu menu__list"><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-1 menu__list-item"><a class="menu__link" href="/zh/v2.7">什么是 Rancher?</a></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--sublist-caret" aria-expanded="false" href="/zh/v2.7/getting-started/overview">开始使用</a></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--sublist-caret" aria-expanded="false" href="/zh/v2.7/how-to-guides/new-user-guides/new-user-guides">操作指南</a></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--sublist-caret menu__link--active" aria-expanded="true" href="/zh/v2.7/reference-guides/best-practices">参考指南</a></div><ul style="display:block;overflow:visible;height:auto" class="menu__list"><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-2 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist" aria-expanded="false" tabindex="0" href="/zh/v2.7/reference-guides/best-practices">最佳实践</a><button aria-label="打开/收起侧边栏菜单「最佳实践」" type="button" class="clean-btn menu__caret"></button></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-2 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist" aria-expanded="false" tabindex="0" href="/zh/v2.7/reference-guides/rancher-manager-architecture">Rancher 架构</a><button aria-label="打开/收起侧边栏菜单「Rancher 架构」" type="button" class="clean-btn menu__caret"></button></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-2 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist" aria-expanded="false" tabindex="0" href="/zh/v2.7/reference-guides/cluster-configuration">集群配置</a><button aria-label="打开/收起侧边栏菜单「集群配置」" type="button" class="clean-btn menu__caret"></button></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-2 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist" aria-expanded="false" tabindex="0" href="/zh/v2.7/reference-guides/single-node-rancher-in-docker">Docker 中的单节点 Rancher</a><button aria-label="打开/收起侧边栏菜单「Docker 中的单节点 Rancher」" type="button" class="clean-btn menu__caret"></button></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-2 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist" aria-expanded="false" tabindex="0" href="/zh/v2.7/reference-guides/backup-restore-configuration">备份和恢复配置</a><button aria-label="打开/收起侧边栏菜单「备份和恢复配置」" type="button" class="clean-btn menu__caret"></button></div></li><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-2 menu__list-item"><a class="menu__link" tabindex="0" href="/zh/v2.7/reference-guides/kubernetes-concepts">Kubernetes 概念</a></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-2 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist" aria-expanded="false" tabindex="0" href="/zh/v2.7/reference-guides/monitoring-v2-configuration">Monitoring 配置</a><button aria-label="打开/收起侧边栏菜单「Monitoring 配置」" type="button" class="clean-btn menu__caret"></button></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-2 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist" aria-expanded="false" tabindex="0" href="/zh/v2.7/reference-guides/prometheus-federator">Prometheus Federator</a><button aria-label="打开/收起侧边栏菜单「Prometheus Federator」" type="button" class="clean-btn menu__caret"></button></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-2 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist" aria-expanded="false" tabindex="0" href="/zh/v2.7/reference-guides/user-settings">用户设置</a><button aria-label="打开/收起侧边栏菜单「用户设置」" type="button" class="clean-btn menu__caret"></button></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-2 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist" aria-expanded="false" tabindex="0" href="/zh/v2.7/reference-guides/cli-with-rancher">Rancher CLI</a><button aria-label="打开/收起侧边栏菜单「Rancher CLI」" type="button" class="clean-btn menu__caret"></button></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-2 menu__list-item"><div class="menu__list-item-collapsible menu__list-item-collapsible--active"><a class="menu__link menu__link--sublist menu__link--active" aria-current="page" aria-expanded="true" tabindex="0" href="/zh/v2.7/reference-guides/about-the-api">关于 API</a><button aria-label="打开/收起侧边栏菜单「关于 API」" type="button" class="clean-btn menu__caret"></button></div><ul style="display:block;overflow:visible;height:auto" class="menu__list"><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-3 menu__list-item"><a class="menu__link" tabindex="0" href="/zh/v2.7/reference-guides/about-the-api/api-tokens">API 令牌</a></li></ul></li><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-2 menu__list-item"><a class="menu__link" tabindex="0" href="/zh/v2.7/reference-guides/rancher-cluster-tools">集群工具:Logging,Monitoring 和可视化</a></li><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-2 menu__list-item"><a class="menu__link" tabindex="0" href="/zh/v2.7/reference-guides/rancher-project-tools">项目工具:Logging,Monitoring 和可视化</a></li><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-2 menu__list-item"><a class="menu__link" tabindex="0" href="/zh/v2.7/reference-guides/system-tools">系统工具</a></li><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-2 menu__list-item"><a class="menu__link" tabindex="0" href="/zh/v2.7/reference-guides/rke1-template-example-yaml">RKE1 示例 YAML</a></li><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-2 menu__list-item"><a class="menu__link" tabindex="0" href="/zh/v2.7/reference-guides/rancher-webhook">Rancher Webhook</a></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-2 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist" aria-expanded="false" tabindex="0" href="/zh/v2.7/reference-guides/rancher-security">Rancher 安全指南</a><button aria-label="打开/收起侧边栏菜单「Rancher 安全指南」" type="button" class="clean-btn menu__caret"></button></div></li></ul></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--sublist-caret" aria-expanded="false" href="/zh/v2.7/integrations-in-rancher/cloud-marketplace">Rancher 中的集成</a></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--sublist-caret" aria-expanded="false" href="/zh/v2.7/faq/general-faq">常见问题</a></div></li><li class="theme-doc-sidebar-item-category theme-doc-sidebar-item-category-level-1 menu__list-item menu__list-item--collapsed"><div class="menu__list-item-collapsible"><a class="menu__link menu__link--sublist menu__link--sublist-caret" aria-expanded="false" href="/zh/v2.7/troubleshooting/general-troubleshooting">故障排除</a></div></li><li class="theme-doc-sidebar-item-link theme-doc-sidebar-item-link-level-1 menu__list-item"><a class="menu__link" href="/zh/v2.7/contribute-to-rancher">参与 Rancher 社区贡献</a></li></ul></nav></div></div></aside><main class="docMainContainer_gTbr"><div class="container padding-top--md padding-bottom--lg"><div class="row"><div class="col docItemCol_VOVn"><div class="docItemContainer_Djhp"><article><nav class="theme-doc-breadcrumbs breadcrumbsContainer_Z_bl" aria-label="页面路径"><ul class="breadcrumbs" itemscope="" itemtype="https://schema.org/BreadcrumbList"><li class="breadcrumbs__item"><a aria-label="主页面" class="breadcrumbs__link" href="/zh/"><svg viewBox="0 0 24 24" class="breadcrumbHomeIcon_YNFT"><path d="M10 19v-5h4v5c0 .55.45 1 1 1h3c.55 0 1-.45 1-1v-7h1.7c.46 0 .68-.57.33-.87L12.67 3.6c-.38-.34-.96-.34-1.34 0l-8.36 7.53c-.34.3-.13.87.33.87H5v7c0 .55.45 1 1 1h3c.55 0 1-.45 1-1z" fill="currentColor"></path></svg></a></li><li class="breadcrumbs__item"><span class="breadcrumbs__link">参考指南</span><meta itemprop="position" content="1"></li><li itemscope="" itemprop="itemListElement" itemtype="https://schema.org/ListItem" class="breadcrumbs__item breadcrumbs__item--active"><span class="breadcrumbs__link" itemprop="name">关于 API</span><meta itemprop="position" content="2"></li></ul></nav><span class="theme-doc-version-badge badge badge--secondary">版本:v2.7</span><div class="tocCollapsible_ETCw theme-doc-toc-mobile tocMobile_ITEo"><button type="button" class="clean-btn tocCollapsibleButton_TO0P">本页总览</button></div><div class="theme-doc-markdown markdown"><header><h1>API</h1></header><h2 class="anchor anchorWithStickyNavbar_LWe7" id="如何使用-api">如何使用 API<a href="#如何使用-api" class="hash-link" aria-label="标题的直接链接" title="标题的直接链接"></a></h2><p>API 有自己的用户界面,你可以从 Web 浏览器访问它。这是查看资源、执行操作以及查看等效 cURL 或 HTTP 请求和响应的一种简单的方法。要访问它:</p><div class="tabs-container tabList__CuJ"><ul role="tablist" aria-orientation="horizontal" class="tabs"><li role="tab" tabindex="0" aria-selected="true" class="tabs__item tabItem_LNqP tabs__item--active">Rancher v2.6.4+</li><li role="tab" tabindex="-1" aria-selected="false" class="tabs__item tabItem_LNqP">Rancher 版本低于 v2.6.4</li></ul><div class="margin-top--md"><div role="tabpanel" class="tabItem_Ymn6"><ol><li>单击右上角的用户头像。</li><li>单击<strong>账号 & API 密钥</strong>。</li><li>在 <strong>API 密钥</strong>下,找到 <strong>API 端点</strong>字段并单击链接。该链接类似于 <code>https://<RANCHER_FQDN>/v3</code>,其中 <code><RANCHER_FQDN></code> 是 Rancher deployment 的完全限定域名。</li></ol></div><div role="tabpanel" class="tabItem_Ymn6" hidden=""><p>转到位于 <code>https://<RANCHER_FQDN>/v3</code> 的 URL 端点,其中 <code><RANCHER_FQDN></code> 是你的 Rancher deployment 的完全限定域名。</p></div></div></div><h2 class="anchor anchorWithStickyNavbar_LWe7" id="认证">认证<a href="#认证" class="hash-link" aria-label="标题的直接链接" title="标题的直接链接"></a></h2><p>API 请求必须包含认证信息。认证是通过 <a href="/zh/v2.7/reference-guides/user-settings/api-keys">API 密钥</a>使用 HTTP 基本认证完成的。API 密钥可以创建新集群并通过 <code>/v3/clusters/</code> 访问多个集群。<a href="/zh/v2.7/how-to-guides/new-user-guides/authentication-permissions-and-global-configuration/manage-role-based-access-control-rbac/cluster-and-project-roles">集群和项目角色</a>会应用于这些键,并限制账号可以查看的集群和项目以及可以执行的操作。</p><p>默认情况下,某些集群级别的 API 令牌是使用无限期 TTL(<code>ttl=0</code>)生成的。换言之,除非你让令牌失效,否则 <code>ttl=0</code> 的 API 令牌永远不会过期。有关如何使 API 令牌失效的详细信息,请参阅 <a href="/zh/v2.7/reference-guides/about-the-api/api-tokens">API 令牌</a>。</p><h2 class="anchor anchorWithStickyNavbar_LWe7" id="发出请求">发出请求<a href="#发出请求" class="hash-link" aria-label="标题的直接链接" title="标题的直接链接"></a></h2><p>该 API 通常是 RESTful 的,但是还具有多种功能。这些功能可以使客户端发现所有内容,因此可以编写通用客户端,而不必为每种资源编写特定代码。有关通用 API 规范的详细信息,请参阅<a href="https://github.com/rancher/api-spec/blob/master/specification.md" target="_blank" rel="noopener noreferrer">此处</a>。</p><ul><li>每种类型都有一个 Schema,这个 Schema 描述了以下内容:<ul><li>用于获取此类资源集合的 URL</li><li>资源可以具有的每个字段及其类型、基本验证规则、是必填还是可选字段等</li><li>在此类资源上可以执行的每个操作,以及它们的输入和输出(也作为 schema)</li><li>允许过滤的每个字段</li><li>集合本身或集合中的单个资源可以使用的 HTTP 操作方法</li></ul></li></ul><ul><li><p>因此,你可以只加载 schema 列表并了解 API 的所有信息。实际上,这是 API 的 UI 工作方式,它不包含特定于 Rancher 本身的代码。每个 HTTP 响应中的 <code>X-Api-Schemas</code> 标头都会发送获取 Schemas 的 URL。你可以按照每个 schema 上的 <code>collection</code> 链接了解要在哪里列出资源,并在返回资源中的其他 <code>links</code> 中获取其他信息。</p></li><li><p>在实践中,你可能只想构造 URL 字符串。我们强烈建议将此限制为在顶层列出的集合 (<code>/v3/<type></code>),或获取特定资源 (<code>/v3/<type>/<id></code>)。除此之外的任何内容都可能在将来的版本中发生更改。</p></li><li><p>资源之间相互之间有联系,称为链接(links)。每个资源都包含一个 <code>links</code> 映射,其中包含链接名称和用于检索该信息的 URL。同样,你应该 <code>GET</code> 资源并遵循 <code>links</code> 映射中的 URL,而不是自己构造这些字符串。</p></li><li><p>大多数资源都有操作(action),表示可以执行某个操作或改变资源的状态。要使用操作,请将 HTTP <code>POST</code> 请求发送到 <code>actions</code> 映射中你想要的操作的 URL。某些操作需要输入或生成输出,请参阅每种类型的独立文档或 schema 以获取具体信息。</p></li><li><p>要编辑资源,请将 HTTP <code>PUT</code> 请求发送到资源上的 <code>links.update</code> 链接,其中包含要更改的字段。如果链接丢失,则你无权更新资源。未知字段和不可编辑的字段将被忽略。</p></li><li><p>要删除资源,请将 HTTP <code>DELETE</code> 请求发送到资源上的 <code>links.remove</code> 链接。如果链接丢失,则你无权更新资源。</p></li><li><p>要创建新资源,HTTP <code>POST</code> 到 schema(即 <code>/v3/<type></code>)中的集合 URL。</p></li></ul><h2 class="anchor anchorWithStickyNavbar_LWe7" id="过滤">过滤<a href="#过滤" class="hash-link" aria-label="标题的直接链接" title="标题的直接链接"></a></h2><p>你可以使用 HTTP 查询参数的公共字段在服务器端过滤大多数集合。<code>filters</code> 映射显示了可以过滤的字段,以及过滤后的值在你发起的请求中是什么。API UI 具有设置过滤和显示适当请求的控件。对于简单的 "equals" 匹配,它只是 <code>field=value</code>。你可以将修饰符添加到字段名称,例如 <code>field_gt=42</code> 表示“字段大于 42”。详情请参阅 <a href="https://github.com/rancher/api-spec/blob/master/specification.md#filtering" target="_blank" rel="noopener noreferrer">API 规范</a>。</p><h2 class="anchor anchorWithStickyNavbar_LWe7" id="排序">排序<a href="#排序" class="hash-link" aria-label="标题的直接链接" title="标题的直接链接"></a></h2><p>你可以使用 HTTP 查询参数的公共字段在服务器端排序大多数集合。<code>sortLinks</code> 映射显示了可用的排序,以及用于获取遵循该排序的集合的 URL。它还包括当前响排序依据的信息(如果指定)。</p><h2 class="anchor anchorWithStickyNavbar_LWe7" id="分页">分页<a href="#分页" class="hash-link" aria-label="标题的直接链接" title="标题的直接链接"></a></h2><p>默认情况下,API 响应以每页 100 个资源的限制进行分页。你可以通过 <code>limit</code> 查询参数进行更改,最大为 1000,例如 <code>/v3/pods?limit=1000</code>。集合响应中的 <code>pagination</code> 映射能让你知道你是否拥有完整的结果集,如果没有,则会指向下一页的链接。</p><h2 class="anchor anchorWithStickyNavbar_LWe7" id="捕获-rancher-api-调用">捕获 Rancher API 调用<a href="#捕获-rancher-api-调用" class="hash-link" aria-label="标题的直接链接" title="标题的直接链接"></a></h2><p>你可以使用浏览器开发人员工具来捕获 Rancher API 的调用方式。例如,你可以按照以下步骤使用 Chrome 开发人员工具来获取用于配置 RKE 集群的 API 调用:</p><ol><li>在 Rancher UI 中,转到<strong>集群管理</strong>并单击<strong>创建</strong>。</li><li>单击某个集群类型。此示例使用 Digital Ocean。</li><li>使用集群名称和节点模板填写表单,但不要单击<strong>创建</strong>。</li><li>在创建集群之前,你需要打开开发人员工具才能看到正在记录的 API 调用。要打开工具,右键单击 Rancher UI,然后单击<strong>检查</strong>。</li><li>在开发者工具中,单击 <strong>Network</strong> 选项卡。</li><li>在 <strong>Network</strong> 选项卡上,确保选择了 <strong>Fetch/XHR</strong>。</li><li>在 Rancher UI 中,单击<strong>创建</strong>。在开发者工具中,你应该会看到一个名为 <code>cluster?_replace=true</code> 的新网络请求。</li><li>右键单击 <code>cluster?_replace=true</code> 并单击<strong>复制 > 复制为 cURL</strong>。</li><li>将结果粘贴到文本编辑器中。你将能够看到 POST 请求,包括被发送到的 URL、所有标头以及请求的完整正文。此命令可用于从命令行创建集群。请注意,请求包含凭证,因此请将请求存储在安全的地方。</li></ol><h3 class="anchor anchorWithStickyNavbar_LWe7" id="启用在-api-中查看">启用在 API 中查看<a href="#启用在-api-中查看" class="hash-link" aria-label="标题的直接链接" title="标题的直接链接"></a></h3><p>你还可以查看针对各自集群和资源捕获的 Rancher API 调用。 默认情况下不启用此功能。 要启用它:</p><ol><li>单击 UI 右上角的 <strong>用户图标</strong>,然后从下拉菜单中选择 <strong>偏好设置</strong></li><li>在<strong>高级功能</strong>部分下,单击<strong>启用"在 API 中查看"</strong></li></ol><p>选中后,<strong>在 API 中查看</strong>链接现在将显示在 UI 资源页面上的 <strong>⋮</strong> 子菜单下。</p></div><footer class="theme-doc-footer docusaurus-mt-lg"><div class="theme-doc-footer-edit-meta-row row"><div class="col"><a href="https://github.com/rancher/rancher-docs/edit/main/versioned_docs/version-2.7/reference-guides/about-the-api/about-the-api.md" target="_blank" rel="noreferrer noopener" class="theme-edit-this-page"><svg fill="currentColor" height="20" width="20" viewBox="0 0 40 40" class="iconEdit_Z9Sw" aria-hidden="true"><g><path d="m34.5 11.7l-3 3.1-6.3-6.3 3.1-3q0.5-0.5 1.2-0.5t1.1 0.5l3.9 3.9q0.5 0.4 0.5 1.1t-0.5 1.2z m-29.5 17.1l18.4-18.5 6.3 6.3-18.4 18.4h-6.3v-6.2z"></path></g></svg>编辑此页</a></div><div class="col lastUpdated_vwxv"><span class="theme-last-updated">最后<!-- -->于 <b><time datetime="2024-04-24T03:44:32.000Z">2024年4月24日</time></b> <!-- -->更新</span></div></div></footer></article><nav class="pagination-nav docusaurus-mt-lg" aria-label="文档分页导航"><a class="pagination-nav__link pagination-nav__link--prev" href="/zh/v2.7/reference-guides/cli-with-rancher/kubectl-utility"><div class="pagination-nav__sublabel">上一页</div><div class="pagination-nav__label">kubectl 实用程序</div></a><a class="pagination-nav__link pagination-nav__link--next" href="/zh/v2.7/reference-guides/about-the-api/api-tokens"><div class="pagination-nav__sublabel">下一页</div><div class="pagination-nav__label">API 令牌</div></a></nav></div></div><div class="col col--3"><div class="tableOfContents_bqdL thin-scrollbar theme-doc-toc-desktop"><ul class="table-of-contents table-of-contents__left-border"><li><a href="#如何使用-api" class="table-of-contents__link toc-highlight">如何使用 API</a></li><li><a href="#认证" class="table-of-contents__link toc-highlight">认证</a></li><li><a href="#发出请求" class="table-of-contents__link toc-highlight">发出请求</a></li><li><a href="#过滤" class="table-of-contents__link toc-highlight">过滤</a></li><li><a href="#排序" class="table-of-contents__link toc-highlight">排序</a></li><li><a href="#分页" class="table-of-contents__link toc-highlight">分页</a></li><li><a href="#捕获-rancher-api-调用" class="table-of-contents__link toc-highlight">捕获 Rancher API 调用</a><ul><li><a href="#启用在-api-中查看" class="table-of-contents__link toc-highlight">启用在 API 中查看</a></li></ul></li></ul></div></div></div></div></main></div></div><footer class="footer footer--dark"><div class="container container-fluid"><div class="footer__bottom text--center"><div class="footer__copyright">Copyright © 2024 SUSE Rancher. All Rights Reserved.</div></div></div></footer></div>
|
||
<script src="/zh/assets/js/runtime~main.7955d3d3.js"></script>
|
||
<script src="/zh/assets/js/main.129d8862.js"></script>
|
||
</body>
|
||
</html> |