mirror of
https://github.com/foo-dogsquared/wiki.git
synced 2025-02-07 09:18:59 +00:00
37 lines
15 KiB
HTML
37 lines
15 KiB
HTML
<!DOCTYPE html><html><head><meta name="viewport" content="width=device-width"/><meta charSet="utf-8"/><title>Command line: kubectl</title><script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script><script id="MathJax-script" async="" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script><script type="text/x-mathjax-config">
|
|
MathJax = {
|
|
tex: {
|
|
inlineMath: [ ['$','$'], ['\(','\)'] ],
|
|
displayMath: [ ['$$','$$'], ['[',']'] ]
|
|
},
|
|
options = {
|
|
processHtmlClass = "math"
|
|
}
|
|
}
|
|
</script><meta name="next-head-count" content="6"/><link rel="preload" href="/wiki/_next/static/css/52fc2ba29703df73922c.css" as="style"/><link rel="stylesheet" href="/wiki/_next/static/css/52fc2ba29703df73922c.css" data-n-g=""/><noscript data-n-css=""></noscript><link rel="preload" href="/wiki/_next/static/chunks/main-ae4733327bd95c4ac325.js" as="script"/><link rel="preload" href="/wiki/_next/static/chunks/webpack-50bee04d1dc61f8adf5b.js" as="script"/><link rel="preload" href="/wiki/_next/static/chunks/framework.9d524150d48315f49e80.js" as="script"/><link rel="preload" href="/wiki/_next/static/chunks/commons.0e1c3f9aa780c2dfe9f0.js" as="script"/><link rel="preload" href="/wiki/_next/static/chunks/pages/_app-8e3d0c58a60ec788aa69.js" as="script"/><link rel="preload" href="/wiki/_next/static/chunks/940643274e605e7596ecea1f2ff8d83317a3fb76.4841a16762f602a59f00.js" as="script"/><link rel="preload" href="/wiki/_next/static/chunks/pages/%5B%5B...slug%5D%5D-1aa198f87ede1cd0e1dc.js" as="script"/></head><body><div id="__next"><main><h1>Command line: kubectl</h1><section class="post-metadata"><span>Date: <!-- -->2021-06-13 00:29:49 +08:00</span><span>Date modified: <!-- -->2021-07-02 16:44:03 +08:00</span></section><nav class="toc"><ol class="toc-level toc-level-1"><li class="toc-item toc-item-h1"><a href="/wiki/cli.kubectl#subcommands" class="toc-link toc-link-h1">Subcommands</a></li><li class="toc-item toc-item-h1"><a href="/wiki/cli.kubectl#examples" class="toc-link toc-link-h1">Examples</a><ol class="toc-level toc-level-2"><li class="toc-item toc-item-h2"><a href="/wiki/cli.kubectl#basic-workflow-example-from-a-beginners-perspective" class="toc-link toc-link-h2">Basic workflow example from a beginner's perspective</a></li></ol></li></ol></nav><p>The main binary when managing <a href="/wiki/tools.kubernetes">Kubernetes</a> clusters.
|
|
</p><h1 id="subcommands">Subcommands</h1><ul><li><p><code class="inline-verbatim">api-resource</code> lists all of the resources it currently supports.
|
|
</p></li><li><p><code class="inline-verbatim">cluster-info</code> prints information of the cluster and the add-ons installed.
|
|
</p></li><li><p><code class="inline-verbatim">create [RESOURCE] [NAME]</code> creates the specified resource with the given name.
|
|
</p><ul><li><p><code class="inline-verbatim">--dry-run</code> just initiates the process and does nothing.
|
|
Useful with <code class="inline-verbatim">-o yaml</code> to create a minimal manifest.
|
|
</p></li><li><p><code class="inline-verbatim">-o [yaml|json|wide]</code> prints the created resource as the specified output.
|
|
Specially useful to create manifests and manage clusters declaratively.
|
|
</p></li></ul></li><li><p><code class="inline-verbatim">describe [RESOURCE] [NAME]</code> prints a detailed description of the given resource.
|
|
</p></li><li><p><code class="inline-verbatim">logs [RESOURCE] [NAME]</code> shows the log printed from the given resource.
|
|
</p></li><li><p><code class="inline-verbatim">explain [RESOURCE]</code> prints an explaination of the given resource — e.g., <code class="inline-code">kubectl explain pods</code>, <code class="inline-code">kubectl explain rs</code>.
|
|
</p></li><li><p><code class="inline-verbatim">get [RESOURCE]</code> list the specified resource from the cluster.
|
|
</p><ul><li><p><code class="inline-verbatim">-o, --output [yaml|json|wide]</code> prints in the specified format.
|
|
You can also print <a href="https://kubernetes.io/docs/reference/kubectl/overview/#custom-columns">the columns</a> you only need.
|
|
</p></li></ul></li><li><p><code class="inline-verbatim">apply</code> applies a manifest, that is, a configuration file.
|
|
</p></li></ul><p>When referring to a specific resource with <code class="inline-verbatim">${RESOURCE}/${NAME}</code> — e.g., <code class="inline-verbatim">namespace/demo</code>, <code class="inline-verbatim">deploy/hello</code>.
|
|
</p><h1 id="examples">Examples</h1><p>As this is a massive tool, this needs massive examples.
|
|
</p><h2 id="basic-workflow-example-from-a-beginners-perspective">Basic workflow example from a beginner's perspective</h2><p>Say you want to deploy your application with Kubernetes akin to Docker with a single container.
|
|
</p><pre class="src-block"><code class="language-bash"># Get the description of the cluster.
|
|
kubectl cluster-info
|
|
|
|
# List all of the supported resources.
|
|
kubectl api-resources
|
|
|
|
# Create a deployment.
|
|
kubectl create deployment/hello-world --image=alpine
|
|
</code></pre><section><h2>Backlinks</h2><ul><li><a href="/wiki/tools.kubernetes">Kubernetes</a></li></ul></section></main></div><script id="__NEXT_DATA__" type="application/json">{"props":{"pageProps":{"metadata":{"date":"\"2021-06-13 00:29:49 +08:00\"","date_modified":"\"2021-07-02 16:44:03 +08:00\"","language":"en","source":""},"title":"Command line: kubectl","hast":{"type":"root","children":[{"type":"element","tagName":"nav","properties":{"className":"toc"},"children":[{"type":"element","tagName":"ol","properties":{"className":"toc-level toc-level-1"},"children":[{"type":"element","tagName":"li","data":{"hookArgs":[{"type":"element","tagName":"h1","properties":{"id":"subcommands"},"children":[{"type":"text","value":"Subcommands"}]}]},"properties":{"className":"toc-item toc-item-h1"},"children":[{"type":"element","tagName":"a","properties":{"className":"toc-link toc-link-h1","href":"/cli.kubectl#subcommands"},"children":[{"type":"text","value":"Subcommands"}]}]},{"type":"element","tagName":"li","data":{"hookArgs":[{"type":"element","tagName":"h1","properties":{"id":"examples"},"children":[{"type":"text","value":"Examples"}]}]},"properties":{"className":"toc-item toc-item-h1"},"children":[{"type":"element","tagName":"a","properties":{"className":"toc-link toc-link-h1","href":"/cli.kubectl#examples"},"children":[{"type":"text","value":"Examples"}]},{"type":"element","tagName":"ol","properties":{"className":"toc-level toc-level-2"},"children":[{"type":"element","tagName":"li","data":{"hookArgs":[{"type":"element","tagName":"h2","properties":{"id":"basic-workflow-example-from-a-beginners-perspective"},"children":[{"type":"text","value":"Basic workflow example from a beginner's perspective"}]}]},"properties":{"className":"toc-item toc-item-h2"},"children":[{"type":"element","tagName":"a","properties":{"className":"toc-link toc-link-h2","href":"/cli.kubectl#basic-workflow-example-from-a-beginners-perspective"},"children":[{"type":"text","value":"Basic workflow example from a beginner's perspective"}]}]}]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"The main binary when managing "},{"type":"element","tagName":"a","properties":{"href":"/tools.kubernetes"},"children":[{"type":"text","value":"Kubernetes"}]},{"type":"text","value":" clusters.\n"}]},{"type":"element","tagName":"h1","properties":{"id":"subcommands"},"children":[{"type":"text","value":"Subcommands"}]},{"type":"element","tagName":"ul","properties":{},"children":[{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"api-resource"}]},{"type":"text","value":" lists all of the resources it currently supports.\n"}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"cluster-info"}]},{"type":"text","value":" prints information of the cluster and the add-ons installed.\n"}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"create [RESOURCE] [NAME]"}]},{"type":"text","value":" creates the specified resource with the given name.\n"}]},{"type":"element","tagName":"ul","properties":{},"children":[{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"--dry-run"}]},{"type":"text","value":" just initiates the process and does nothing.\n Useful with "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"-o yaml"}]},{"type":"text","value":" to create a minimal manifest.\n"}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"-o [yaml|json|wide]"}]},{"type":"text","value":" prints the created resource as the specified output.\n Specially useful to create manifests and manage clusters declaratively.\n"}]}]}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"describe [RESOURCE] [NAME]"}]},{"type":"text","value":" prints a detailed description of the given resource.\n"}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"logs [RESOURCE] [NAME]"}]},{"type":"text","value":" shows the log printed from the given resource.\n"}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"explain [RESOURCE]"}]},{"type":"text","value":" prints an explaination of the given resource — e.g., "},{"type":"element","tagName":"code","properties":{"className":["inline-code"]},"children":[{"type":"text","value":"kubectl explain pods"}]},{"type":"text","value":", "},{"type":"element","tagName":"code","properties":{"className":["inline-code"]},"children":[{"type":"text","value":"kubectl explain rs"}]},{"type":"text","value":".\n"}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"get [RESOURCE]"}]},{"type":"text","value":" list the specified resource from the cluster.\n"}]},{"type":"element","tagName":"ul","properties":{},"children":[{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"-o, --output [yaml|json|wide]"}]},{"type":"text","value":" prints in the specified format.\n You can also print "},{"type":"element","tagName":"a","properties":{"href":"https://kubernetes.io/docs/reference/kubectl/overview/#custom-columns"},"children":[{"type":"text","value":"the columns"}]},{"type":"text","value":" you only need.\n"}]}]}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"apply"}]},{"type":"text","value":" applies a manifest, that is, a configuration file.\n"}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"When referring to a specific resource with "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"${RESOURCE}/${NAME}"}]},{"type":"text","value":" — e.g., "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"namespace/demo"}]},{"type":"text","value":", "},{"type":"element","tagName":"code","properties":{"className":["inline-verbatim"]},"children":[{"type":"text","value":"deploy/hello"}]},{"type":"text","value":".\n"}]},{"type":"element","tagName":"h1","properties":{"id":"examples"},"children":[{"type":"text","value":"Examples"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"As this is a massive tool, this needs massive examples.\n"}]},{"type":"element","tagName":"h2","properties":{"id":"basic-workflow-example-from-a-beginners-perspective"},"children":[{"type":"text","value":"Basic workflow example from a beginner's perspective"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Say you want to deploy your application with Kubernetes akin to Docker with a single container.\n"}]},{"type":"element","tagName":"pre","properties":{"className":["src-block"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-bash"]},"children":[{"type":"text","value":"# Get the description of the cluster.\nkubectl cluster-info\n\n# List all of the supported resources.\nkubectl api-resources\n\n# Create a deployment.\nkubectl create deployment/hello-world --image=alpine\n"}]}]}]},"backlinks":[{"path":"/tools.kubernetes","title":"Kubernetes"}]},"__N_SSG":true},"page":"/[[...slug]]","query":{"slug":["cli.kubectl"]},"buildId":"Ie9t5zutrXP6Of75Cb5xF","assetPrefix":"/wiki","nextExport":false,"isFallback":false,"gsp":true}</script><script nomodule="" src="/wiki/_next/static/chunks/polyfills-99d808df29361cf7ffb1.js"></script><script src="/wiki/_next/static/chunks/main-ae4733327bd95c4ac325.js" async=""></script><script src="/wiki/_next/static/chunks/webpack-50bee04d1dc61f8adf5b.js" async=""></script><script src="/wiki/_next/static/chunks/framework.9d524150d48315f49e80.js" async=""></script><script src="/wiki/_next/static/chunks/commons.0e1c3f9aa780c2dfe9f0.js" async=""></script><script src="/wiki/_next/static/chunks/pages/_app-8e3d0c58a60ec788aa69.js" async=""></script><script src="/wiki/_next/static/chunks/940643274e605e7596ecea1f2ff8d83317a3fb76.4841a16762f602a59f00.js" async=""></script><script src="/wiki/_next/static/chunks/pages/%5B%5B...slug%5D%5D-1aa198f87ede1cd0e1dc.js" async=""></script><script src="/wiki/_next/static/Ie9t5zutrXP6Of75Cb5xF/_buildManifest.js" async=""></script><script src="/wiki/_next/static/Ie9t5zutrXP6Of75Cb5xF/_ssgManifest.js" async=""></script></body></html> |