飞雪团队

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 11804|回复: 0

Docker 与 K8S学习笔记(二十二)—— 高效使用kubectl的小技巧

[复制链接]

7559

主题

7647

帖子

2万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
25007
发表于 2022-2-12 14:35:42 | 显示全部楼层 |阅读模式

9 n% k3 t! i# y<p>kubectl作为我们主要的操作K8S的工具,其具备非常丰富的功能,但是如果不经过打磨,使用起来还是存在诸多不便,今天我们来看看如何将我们的kubectl打磨的更加易用。</p>( G' _4 F3 x+ _/ u6 X1 P, V! U
<p>&nbsp;</p>& o6 C. z7 `8 l
<p>一、命令自动补全</p>
9 R& t7 s8 o. i" d- g+ P$ `' I<p>kubectl中提供非常多的命令,如果每一次都要手动一个字符一个字符的敲未免太累了,那么如何配置自动补全呢?这里以ubuntu系统为例:</p>0 G0 ?; ^+ H: C
<p>1、安装auto-completion工具</p>* P( L! q8 {1 |  t4 F( ], v8 }
<div class="cnblogs_code">& O, N% S1 u) S. ?6 Y
<pre>$ <span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> apt update
! T0 q# M3 a, N3 ^Hit:</span><span style="color: rgba(128, 0, 128, 1)">1</span> http:<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">archive.ubuntu.com/ubuntu bionic InRelease</span>
& H5 P# H8 f- }6 `) dHit:<span style="color: rgba(128, 0, 128, 1)">2</span> http:<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">security.ubuntu.com/ubuntu bionic-security InRelease</span>3 Y- a8 W" b9 e: L9 T2 c, q
Hit:<span style="color: rgba(128, 0, 128, 1)">3</span> http:<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">archive.ubuntu.com/ubuntu bionic-updates InRelease</span>4 M: O, ?% [3 p) p+ I$ ~" y/ y
Hit:<span style="color: rgba(128, 0, 128, 1)">4</span> https:<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">download.docker.com/linux/ubuntu bionic InRelease</span>5 J& b! R8 [0 A+ X3 Q( ^. G
Hit:<span style="color: rgba(128, 0, 128, 1)">5</span> http:<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">archive.ubuntu.com/ubuntu bionic-backports InRelease</span>+ [7 {3 ]1 E) I3 a( E5 i* c* @
<span style="color: rgba(0, 0, 0, 1)">Reading package lists... Done8 c% M3 ^/ R: W$ S' }. h! Y
Building dependency tree
& i" _% p, g  ]0 }3 A/ qReading state information... Done) h1 u) a; G& G/ S1 D" b! q9 n$ _
</span><span style="color: rgba(128, 0, 128, 1)">144</span> packages can be upgraded. Run <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">apt list --upgradable</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)"> to see them.
; k. k! l4 m& v1 t( ~7 I5 F) x$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span> apt <span style="color: rgba(0, 0, 255, 1)">install</span> bash-<span style="color: rgba(0, 0, 0, 1)">completion3 j: C9 f7 U  o9 u! _2 W
Reading package lists... Done6 N9 X3 h# f8 x, c6 x+ c
Building dependency tree
) g& ], L1 F  }  U2 O- v( MReading state information... Done$ ~  {7 G4 V9 C( h! `, X3 Q
bash</span>-completion is already the newest version (<span style="color: rgba(128, 0, 128, 1)">1</span>:<span style="color: rgba(128, 0, 128, 1)">2.8</span>-<span style="color: rgba(0, 0, 0, 1)">1ubuntu1).& \. u5 k$ S& l6 n/ I: W: Q" ~
</span><span style="color: rgba(128, 0, 128, 1)">0</span> upgraded, <span style="color: rgba(128, 0, 128, 1)">0</span> newly installed, <span style="color: rgba(128, 0, 128, 1)">0</span> to remove and <span style="color: rgba(128, 0, 128, 1)">144</span> not upgraded.</pre>7 V* \% m7 u1 e, u, @
</div>
& E7 r" o$ i: k% Z<p>PS:如果是centos系统,则使用<span class="js_darkmode__0" data-darkmode-color-16446330660319="rgb(0, 104, 255)" data-darkmode-original-color-16446330660319="#fff|rgb(0, 82, 255)" data-style="color: rgb(0, 82, 255);"><strong data-darkmode-color-16446330660319="rgb(0, 104, 255)" data-darkmode-original-color-16446330660319="#fff|rgb(0, 82, 255)">yum&nbsp;install&nbsp;bash-completion -y</strong>命令安装</span></p>
- H5 [! J0 Q/ D! j, E<p>2、<span class="js_darkmode__1" data-darkmode-color-16446330660319="rgb(163, 163, 163)" data-darkmode-original-color-16446330660319="#fff|rgb(0, 0, 0)" data-style="color: rgb(0, 0, 0);">配置自动补全<br></span></p>
/ f7 h$ e0 [& E) q<p><span class="js_darkmode__2" data-darkmode-color-16446330660319="rgb(163, 163, 163)" data-darkmode-original-color-16446330660319="#fff|rgb(0, 0, 0)" data-style="color: rgb(0, 0, 0);"><strong data-darkmode-color-16446330660319="rgb(163, 163, 163)" data-darkmode-original-color-16446330660319="#fff|rgb(0, 0, 0)">Bash</strong>:</span></p>) z# U7 R5 }# {
<div class="cnblogs_code">6 D1 E; F; D, V6 |9 V6 _+ P; b
<pre>source &lt;<span style="color: rgba(0, 0, 0, 1)">(kubectl completion bash)# r* k% J/ E* O8 I; {) s$ Y8 V
</span><span style="color: rgba(0, 0, 255, 1)">echo</span> <span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">source &lt;(kubectl completion bash)</span><span style="color: rgba(128, 0, 0, 1)">"</span> &gt;&gt; ~/.bashrc</pre>
1 S' J( \, q5 f; R</div>5 J: }. O" V, b" h# T
<p><strong>Zsh</strong>:</p>& g4 b" P8 p+ I/ K5 v+ z
<div class="cnblogs_code">; \6 W; }7 ?% S* O- _  q& C" Q
<pre>source &lt;<span style="color: rgba(0, 0, 0, 1)">(kubectl completion zsh), E  I8 O7 h9 o0 Y& j+ D
</span><span style="color: rgba(0, 0, 255, 1)">echo</span> <span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">[[ $commands[kubectl] ]] &amp;&amp; source &lt;(kubectl completion zsh)</span><span style="color: rgba(128, 0, 0, 1)">"</span> &gt;&gt; ~/.zshrc</pre>3 K# {. c( t. j- l/ S# C6 {
</div>
: P9 I1 }: }8 `<p>配置后就可以通过Tab键自动补全命令啦!</p>( H, S6 s  z: A) p* o" A$ `
<p>&nbsp;</p>
( W2 n$ Y) Z$ e3 [9 b/ y<p>二、配置kubectl别名</p>$ S& X  w# @" T: E; p
<p>我们可以通过设置别名简化kubectl命令,编辑.bashrc文件,添加如下内容:</p>8 d2 ]9 U3 r; H8 T" p
<div class="cnblogs_code">+ i: d6 e4 b& M1 _% N$ w
<pre>alias <span style="color: rgba(0, 0, 255, 1)">sudo</span>=<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">sudo </span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">, J* _6 U6 y* M( s2 z) H" V9 ]
alias k</span>=<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">kubectl</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">
( X( E0 O# s9 c& c$ c" ~, Oalias ka</span>=<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">kubectl apply --recursive -f</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">; d( e+ S' w3 E2 N% `2 Q
alias kex</span>=<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">kubectl exec -i -t</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">
  v& G" ?- y) H2 s& falias klo</span>=<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">kubectl logs -f</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">& z5 y: e3 W0 {0 M5 d# i
alias kg</span>=<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">kubectl get</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">; j8 d$ w; o& h0 G( y* }; h
alias kd</span>=<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">kubectl describe</span><span style="color: rgba(128, 0, 0, 1)">'</span></pre>9 P- K; Y9 g. s+ M. G- b) m
</div>
, K+ T/ b& q* i3 Z2 y  O$ t<p><span class="js_darkmode__4" data-darkmode-color-16446330660319="rgb(0, 104, 255)" data-darkmode-original-color-16446330660319="#fff|rgb(0, 82, 255)" data-style="color: rgb(0, 82, 255);"><strong data-darkmode-color-16446330660319="rgb(0, 104, 255)" data-darkmode-original-color-16446330660319="#fff|rgb(0, 82, 255)">PS:alias sudo是为了解决sudo下别名不可用问题</strong><br></span></p>6 J. I, |  s( D# ]6 v6 [+ @
<p><span class="js_darkmode__5" data-darkmode-color-16446330660319="rgb(163, 163, 163)" data-darkmode-original-color-16446330660319="#fff|rgb(0, 0, 0)" data-style="color: rgb(0, 0, 0);">保存后记得执行 source ~/.bashrc哈,接着我们体验下:</span></p>
/ r- |* t; m  ]) _! Y4 p4 C# c3 T<div class="cnblogs_code">: }1 P/ `/ C" }* h& o$ ^# f/ v
<pre>$ <span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> ka webapp_pod.yaml, M8 `" _6 t" N: \* ~
pod</span>/<span style="color: rgba(0, 0, 0, 1)">webapp created
. T( S2 {( C8 k/ e$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> kg pods
7 w& I2 [8 }5 yNAME     READY   STATUS              RESTARTS   AGE
5 t# ?; B; a* Z; F+ o& owebapp   </span><span style="color: rgba(128, 0, 128, 1)">0</span>/<span style="color: rgba(128, 0, 128, 1)">2</span>     ContainerCreating   <span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">          7s7 D* }& g3 M% |. ?) B
$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> kd pod webapp
6 s7 U, p$ ]% w* M# `Name:         webapp: i2 }$ B' E5 e7 o& {
Namespace:    default
( e" V7 _2 @% }4 l" OPriority:     </span><span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">
! [1 V4 n( W/ S- CNode:         ayato</span>/<span style="color: rgba(128, 0, 128, 1)">172.16</span>.<span style="color: rgba(128, 0, 128, 1)">194.135</span><span style="color: rgba(0, 0, 0, 1)">3 \4 n9 t" A$ A" ]: J, j
Start Time:   Wed, </span><span style="color: rgba(128, 0, 128, 1)">09</span> Feb <span style="color: rgba(128, 0, 128, 1)">2022</span> <span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">44</span> +<span style="color: rgba(128, 0, 128, 1)">0000</span><span style="color: rgba(0, 0, 0, 1)">
+ O# I0 g; U$ g' `. O9 _Labels:       app</span>=<span style="color: rgba(0, 0, 0, 1)">webapp
9 L2 u8 @* Z5 A! j, JAnnotations:  </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">: b* O3 l6 Z6 {7 V1 ~* X+ l
Status:       Running
8 B4 e. P- k& {IP:           </span><span style="color: rgba(128, 0, 128, 1)">172.17</span>.<span style="color: rgba(128, 0, 128, 1)">0.6</span><span style="color: rgba(0, 0, 0, 1)">
( f3 f% u* ~$ VIPs:- _9 z% A) {! c7 n1 [) b
  IP:  </span><span style="color: rgba(128, 0, 128, 1)">172.17</span>.<span style="color: rgba(128, 0, 128, 1)">0.6</span><span style="color: rgba(0, 0, 0, 1)">) J# Z# F% q/ n6 \
Containers:& c( E* d& [- l7 F/ W
  webapp:2 @- Z; u: g: [' t2 i6 u
    Container ID:   docker:</span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">d9ddf9dd47de12b53f2119bf75df6706bee2e7711509638ad52adc9addeda704</span>
- v2 f; S+ \7 }) B/ a3 Z8 F    Image:          <span style="color: rgba(128, 0, 128, 1)">172.16</span>.<span style="color: rgba(128, 0, 128, 1)">194.135</span>:<span style="color: rgba(128, 0, 128, 1)">5000</span>/webapp:<span style="color: rgba(128, 0, 128, 1)">1.0</span><span style="color: rgba(0, 0, 0, 1)">
9 k+ u9 m% \+ ~3 p% p3 W    Image ID:       docker</span>-pullable:<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">172.16.194.135:5000/webapp@sha256:df3a447a013ada0642dec67bb31976f42f1a0699a68873d0452f514fa24e5c77</span>
) f3 D# t- n4 f5 o( a+ L    Port:           <span style="color: rgba(128, 0, 128, 1)">5000</span>/<span style="color: rgba(0, 0, 0, 1)">TCP
7 g) {. }7 W) g6 D5 a    Host Port:      </span><span style="color: rgba(128, 0, 128, 1)">0</span>/<span style="color: rgba(0, 0, 0, 1)">TCP
0 q# i1 a$ p4 F+ N3 k2 C    State:          Running9 Y. R7 F% w0 C
      Started:      Wed, </span><span style="color: rgba(128, 0, 128, 1)">09</span> Feb <span style="color: rgba(128, 0, 128, 1)">2022</span> <span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">46</span> +<span style="color: rgba(128, 0, 128, 1)">0000</span><span style="color: rgba(0, 0, 0, 1)">
- v2 w  ~1 `/ e& r1 G& U    Ready:          True( n1 R* Y6 x7 t
    Restart Count:  </span><span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">
/ {( |; b' j( Q, q! D+ x    Environment:    </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">* q: j8 s& x' |) i2 g
    Mounts:
9 R9 ], k* s" ^8 y      </span>/tmp from webapp-<span style="color: rgba(0, 0, 0, 1)">logs (rw); I& f! c: _1 j. m# ?, ]* H
      </span>/var/run/secrets/kubernetes.io/serviceaccount from default-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h (ro)% U2 M3 P$ e1 t. z& Y: f; r
  busybox:4 I7 Z+ {( o/ k' R
    Container ID:  docker:</span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">6a6a35a628a782fc643af3dd49986bbc77c23de1ae4726bc521c77f61abbbf5d</span>
0 r" R8 u6 y0 w; H; o<span style="color: rgba(0, 0, 0, 1)">    Image:         busybox/ y& T1 _. h( q; W- {- S7 D
    Image ID:      docker</span>-pullable:<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">busybox@sha256:afcc7f1ac1b49db317a7196c902e61c6c3c4607d63599ee1a82d702d249a0ccb</span>( B5 J7 e/ y5 x9 }2 A# {
    Port:          &lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">
2 X, h) [$ _8 |% G: i7 D    Host Port:     </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">
- t3 O, Z( @0 N9 x' S- h    Command:
8 C6 ^3 X4 `! i+ C7 O      </span><span style="color: rgba(0, 0, 255, 1)">sh</span>
/ H9 F$ |4 b5 H7 K5 Y. a$ H! P0 L      -<span style="color: rgba(0, 0, 0, 1)">c
9 C/ h9 m# a: c5 O  k, Q      </span><span style="color: rgba(0, 0, 255, 1)">tail</span> -f /logs/<span style="color: rgba(0, 0, 0, 1)">log.out. X1 B/ e. I+ [
    State:          Running' S% H2 h' r# K7 O# w
      Started:      Wed, </span><span style="color: rgba(128, 0, 128, 1)">09</span> Feb <span style="color: rgba(128, 0, 128, 1)">2022</span> <span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">06</span>:<span style="color: rgba(128, 0, 128, 1)">53</span> +<span style="color: rgba(128, 0, 128, 1)">0000</span><span style="color: rgba(0, 0, 0, 1)">( ?4 o9 ~+ F3 w2 U: s+ T  D
    Ready:          True
; W, |: N$ @* q; M) `8 C    Restart Count:  </span><span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">/ x( ~1 n: e& @, F  L
    Environment:    </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">
. M# q- K5 s2 x  }+ q    Mounts:+ H% E9 b2 T/ W
      </span>/logs from webapp-<span style="color: rgba(0, 0, 0, 1)">logs (rw)
0 }: t7 g" N9 N+ W9 ?  _) P      </span>/var/run/secrets/kubernetes.io/serviceaccount from default-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h (ro)
9 M% N- y+ K7 e; u5 `% G3 h1 O  ^4 JConditions:
( i" z" z1 K; K! _0 F  Type              Status
) F( D: X4 R- B- O  Initialized       True
# t0 h2 L9 U; h$ L. A/ b* N8 e  Ready             True
- s0 v( h" s/ g1 N: I  ContainersReady   True
& _- Z1 u( e" k  G; C4 Z" B  PodScheduled      True
. Y* N9 w# s+ u/ `# v+ v3 y+ SVolumes:
2 g! m. L" l/ k, t9 _  webapp</span>-<span style="color: rgba(0, 0, 0, 1)">logs:2 X3 ~7 y7 H- _* N0 V; J+ D8 A
    Type:       EmptyDir (a temporary directory that shares a pod</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">s lifetime)</span>8 S( D/ Q3 ]2 T
<span style="color: rgba(0, 0, 0, 1)">    Medium:2 x. N  l& w2 G
    SizeLimit:  </span>&lt;unset&gt;<span style="color: rgba(0, 0, 0, 1)">
6 o- P6 d9 V6 ^5 J" r" F: h! ^  default</span>-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h:
) z0 @% }3 p; z0 t( a    Type:        Secret (a volume populated by a Secret): C  z6 J  f: H+ C
    SecretName:  default</span>-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h
. [: {! a/ K, O% j    Optional:    </span><span style="color: rgba(0, 0, 255, 1)">false</span><span style="color: rgba(0, 0, 0, 1)">8 A! a0 w! H* N( C+ o% `
QoS Class:       BestEffort9 ]# [6 `" \+ {7 g$ `  y0 o
Node</span>-Selectors:  &lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">" y% Y2 w. ?$ G; s# h: H, G
Tolerations:     node.kubernetes.io</span>/not-ready:NoExecute op=Exists <span style="color: rgba(0, 0, 255, 1)">for</span><span style="color: rgba(0, 0, 0, 1)"> 300s
1 I! x4 @; K* t5 X# w0 K0 c6 I5 X                 node.kubernetes.io</span>/unreachable:NoExecute op=Exists <span style="color: rgba(0, 0, 255, 1)">for</span><span style="color: rgba(0, 0, 0, 1)"> 300s
! ^, a. A: c! t2 OEvents:% G# Y# S% u$ U' m! r
  Type    Reason     Age    From               Message- O% D& f1 F" a( U
  </span>----    ------     ----   ----               -------<span style="color: rgba(0, 0, 0, 1)">
7 H5 C, c' {) J  Normal  Scheduled  2m23s  default</span>-scheduler  Successfully assigned default/<span style="color: rgba(0, 0, 0, 1)">webapp to ayato
8 u: t" ^4 y4 Q8 F; `  Normal  Pulled     2m22s  kubelet            Container image </span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">172.16.194.135:5000/webapp:1.0</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)"> already present on machine" g  M* ]3 r4 I1 U
  Normal  Created    2m21s  kubelet            Created container webapp( e/ C+ _; Z' C; P7 V
  Normal  Started    2m21s  kubelet            Started container webapp  x2 X$ n0 q+ _  ~: p7 h$ v" f
  Normal  Pulling    2m21s  kubelet            Pulling image </span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">busybox</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)">1 f3 R) b: v! q7 v/ j4 z
  Normal  Pulled     15s    kubelet            Successfully pulled image </span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">busybox</span><span style="color: rgba(128, 0, 0, 1)">"</span> <span style="color: rgba(0, 0, 255, 1)">in</span> <span style="color: rgba(128, 0, 128, 1)">14</span><span style="color: rgba(0, 0, 0, 1)">.633078305s# U$ P0 V9 N/ L& e
  Normal  Created    15s    kubelet            Created container busybox
1 f( y9 y, B2 V1 m  Normal  Started    14s    kubelet            Started container busybox</span></pre>
, y) z: f# J! `0 U% {</div>. \5 s2 |# V" V. r7 I! {
<p>真的是飞一般的感觉!!!</p>2 k8 M8 Y9 R! x; S$ ~8 V0 q
<p>&nbsp;</p>) c& D9 Y3 G# A7 O% }* T
<p>三、Context和Namespace切换</p>
9 p2 P) t" [) x- a) y- c<p>我们在公司的容器平台上使用kubectl时,经常需要切换context和namespace,导致命令非常繁琐,那有没有简便的方式呢?—— kubectx</p>
6 {/ f: O: `9 G/ z7 ~5 M<p>kubectx安装</p>
/ T- ?5 t4 `3 x& T( F+ q6 A<div class="cnblogs_code">
+ w) ?8 x: Z# z* v<pre>$ <span style="color: rgba(0, 0, 255, 1)">sudo</span> git clone https:<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">github.com/ahmetb/kubectx /opt/kubectx</span>
8 `5 }- U% T3 f' [2 U! |Cloning into <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">/opt/kubectx</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">...
' q' l% @( u8 G5 U0 j5 qremote: Enumerating objects: </span><span style="color: rgba(128, 0, 128, 1)">1457</span>, <span style="color: rgba(0, 0, 255, 1)">done</span><span style="color: rgba(0, 0, 0, 1)">.
' z3 N2 u9 U% [1 X- Z' w. t: f+ cremote: Counting objects: </span><span style="color: rgba(128, 0, 128, 1)">100</span>% (<span style="color: rgba(128, 0, 128, 1)">172</span>/<span style="color: rgba(128, 0, 128, 1)">172</span>), <span style="color: rgba(0, 0, 255, 1)">done</span><span style="color: rgba(0, 0, 0, 1)">.
' O: B) a$ j# w6 c. T( \remote: Compressing objects: </span><span style="color: rgba(128, 0, 128, 1)">100</span>% (<span style="color: rgba(128, 0, 128, 1)">115</span>/<span style="color: rgba(128, 0, 128, 1)">115</span>), <span style="color: rgba(0, 0, 255, 1)">done</span><span style="color: rgba(0, 0, 0, 1)">.9 P+ y$ B+ h8 D3 y* O
remote: Total </span><span style="color: rgba(128, 0, 128, 1)">1457</span> (delta <span style="color: rgba(128, 0, 128, 1)">85</span>), reused <span style="color: rgba(128, 0, 128, 1)">97</span> (delta <span style="color: rgba(128, 0, 128, 1)">51</span>), pack-reused <span style="color: rgba(128, 0, 128, 1)">1285</span><span style="color: rgba(0, 0, 0, 1)">
& O# ]* T1 Q3 |4 Q$ {) q! w* W4 yReceiving objects: </span><span style="color: rgba(128, 0, 128, 1)">100</span>% (<span style="color: rgba(128, 0, 128, 1)">1457</span>/<span style="color: rgba(128, 0, 128, 1)">1457</span>), <span style="color: rgba(128, 0, 128, 1)">905.30</span> KiB | <span style="color: rgba(128, 0, 128, 1)">69.00</span> KiB/s, <span style="color: rgba(0, 0, 255, 1)">done</span><span style="color: rgba(0, 0, 0, 1)">.
) H) c/ {/ D+ [- n/ _Resolving deltas: </span><span style="color: rgba(128, 0, 128, 1)">100</span>% (<span style="color: rgba(128, 0, 128, 1)">817</span>/<span style="color: rgba(128, 0, 128, 1)">817</span>), <span style="color: rgba(0, 0, 255, 1)">done</span><span style="color: rgba(0, 0, 0, 1)">.7 Y, {6 @& R1 P( r9 e
$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span> <span style="color: rgba(0, 0, 255, 1)">ln</span> -s /opt/kubectx/kubens /usr/local/bin/kubectl-<span style="color: rgba(0, 0, 0, 1)">ns
& w- h5 w% T2 f, h6 z$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span> <span style="color: rgba(0, 0, 255, 1)">ln</span> -s /opt/kubectx/kubectx /usr/local/bin/kubectl-ctx</pre>
- g: n( w3 s9 [6 J9 P1 r0 E</div>
/ L1 e1 ?! E7 n- I<p>我们来看一下效果:</p>4 Q+ X4 ]) V% {, U9 B
<div class="cnblogs_code">
( q4 f# l" R! a" B% C( ~+ S8 r<pre>$ <span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ctx
% r  y& n) W9 B0 |! r9 Q! \) eminikube
/ X. Q& Y, k0 t( m- ]$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ctx minikube
7 ?1 x/ x  y% ISwitched to context </span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">minikube</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)">.
  b$ k) D) E- A4 B. ~' |$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ns
6 [2 t, g0 B) |6 h  _default
, U+ k4 `3 ~2 [" o0 B1 _% nkube</span>-node-<span style="color: rgba(0, 0, 0, 1)">lease
* x5 c$ q- L( y  zkube</span>-<span style="color: rgba(0, 0, 0, 1)">public
" m1 t% T, v" X6 d9 X% `! |kube</span>-<span style="color: rgba(0, 0, 0, 1)">system+ k( e8 X! Z* }; {  Y/ l7 E4 L2 `
kubernetes</span>-<span style="color: rgba(0, 0, 0, 1)">dashboard
9 d0 R  W$ x# j, C/ d$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span> k ns kube-<span style="color: rgba(0, 0, 0, 1)">public$ _: Y7 u$ h1 A4 b9 g5 E0 M
Context </span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">minikube</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)"> modified.
$ ?  S- Y1 L5 c/ O! I2 K4 k) KActive namespace is </span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">kube-public</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)">.
2 b7 }% m8 F9 K* X  A1 `$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ns default
+ h! K) \8 w7 c# E) NContext </span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">minikube</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)"> modified., u, x5 ?. S( N( {$ x1 F
Active namespace is </span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">default</span><span style="color: rgba(128, 0, 0, 1)">"</span>.</pre>
+ {0 @/ q# r! g2 e6 b" l3 x</div>
8 M( h6 a" B. F( l$ b# R/ T) }" V<p>&nbsp;</p>& d' ~' H  b9 I0 K' o. ?  I
<p>四、跟踪查看多个Pod的日志</p>
$ L$ w# V+ J" p# e<p>我们一般使用kubectl logs命令查看Pod日志,但是它不能通过-f参数同时跟踪查看多个Pod日志,这就不方便了,毕竟实际生产环境中每个服务都会有多个Pod,这时我们可以使用stern这个工具,它具备如下能力:</p>
# a5 P, B) E3 `. h% Z<ul class="list-paddingleft-2">, R  {$ z3 c9 Z2 \6 p0 G
<li>4 ]5 C1 c% `% c2 m: N
<p>允许使用正则表达式来选择需要查看的PodName</p>0 H6 Q- u/ T5 u  }) T
</li>5 w8 ?2 d$ K& c: [0 {+ g
<li>
" [8 k0 O- W8 D  d3 K: c( j# d<p>为不同 Pod 的日志展示不同的颜色</p>
" q1 d! V& W' G2 z& ]2 y/ Z' c</li>
' X. ]! s3 c" S8 {0 @4 b<li>/ e, |' J5 j& V8 F3 F/ m
<p>跟踪日志过程中假如有符合规则的新 Pod 被创建, 那么会自动添加到输出中</p>
. ]2 }+ y4 |$ y</li>
8 D9 q$ W5 {% p" m6 l) ^</ul>
$ q8 a' t& U& |* ~3 `+ g; m<p>首先安装stern(下载stern时可能较慢可以多试几次):</p>* F5 W3 u# i0 U1 G, i+ r( \
<div class="cnblogs_code">2 r- }  U* J7 R
<pre><span style="color: rgba(0, 0, 255, 1)">wget</span> https:<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">github.com/wercker/stern/releases/download/1.11.0/stern_linux_amd64</span>1 X. M- x" A3 L; P2 B9 c2 j9 h9 ~
<span style="color: rgba(0, 0, 255, 1)">sudo</span> <span style="color: rgba(0, 0, 255, 1)">mv</span> stern_linux_amd64 /usr/local/bin/kubectl-<span style="color: rgba(0, 0, 255, 1)">tail</span>
! Y( O1 |% i! [- T3 N# X  \- s<span style="color: rgba(0, 0, 255, 1)">sudo</span> chomd +x /usr/local/bin/kubectl-<span style="color: rgba(0, 0, 255, 1)">tail</span></pre>9 Y: b, U% h0 R4 q1 N: [* N. q
</div>
/ l5 o$ `( U; [& g% [" a' e" p<p>安装完毕后让我一起感受一下stern的魅力吧,我的Pod里面有两个容器:webapp和busybox,如果使用kubectl logs 还得指定具体的容器,而使用stern就没有这样的限制。</p>8 n5 Z8 ^& v& a' L) T6 m
<div class="cnblogs_code">6 b: Q( ^5 U* t9 \, t3 l2 \
<pre>$ <span style="color: rgba(0, 0, 255, 1)">sudo</span> k <span style="color: rgba(0, 0, 255, 1)">tail</span><span style="color: rgba(0, 0, 0, 1)"> .% e. x/ F7 j5 `1 J$ @1 G# P: G& k" e
</span>+<span style="color: rgba(0, 0, 0, 1)"> webapp › busybox
7 e7 l* ?1 X3 i2 E' b8 ]: x# q</span>+<span style="color: rgba(0, 0, 0, 1)"> webapp › webapp
0 K, G1 G1 `  twebapp busybox </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">53.197</span> [INFO ] [main] [org.apache.coyote.http11.Http11NioProtocol] Initializing ProtocolHandler [<span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">http-nio-4567</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)">]
' f( b9 r1 K0 Y) f/ \webapp busybox </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">53.200</span><span style="color: rgba(0, 0, 0, 1)"> [INFO ] [main] [org.apache.catalina.core.StandardService] Starting service [Tomcat]
9 q0 m, n+ M7 V5 T; c1 o4 Fwebapp busybox </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">53.201</span> [INFO ] [main] [org.apache.catalina.core.StandardEngine] Starting Servlet engine: [Apache Tomcat/<span style="color: rgba(128, 0, 128, 1)">9.0</span>.<span style="color: rgba(128, 0, 128, 1)">41</span><span style="color: rgba(0, 0, 0, 1)">]
) |$ }3 H* n8 B6 \+ _; @4 \7 gwebapp busybox </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">53.324</span> [INFO ] [main] [org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/<span style="color: rgba(0, 0, 0, 1)">]] Initializing Spring embedded WebApplicationContext
$ Z7 a) l9 ^: w( g. v" ]" |5 Z) t$ Iwebapp busybox </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">53.325</span> [INFO ] [main] [org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext] Root WebApplicationContext: initialization completed <span style="color: rgba(0, 0, 255, 1)">in</span> <span style="color: rgba(128, 0, 128, 1)">2952</span><span style="color: rgba(0, 0, 0, 1)"> ms
3 i9 |6 H5 W7 ~  n8 Nwebapp busybox </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">53.801</span> [INFO ] [main] [org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor] Initializing ExecutorService <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">applicationTaskExecutor</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">$ \5 i/ G6 q8 R: Y6 V* }
webapp busybox </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">54.264</span> [WARN ] [main] [org.springframework.boot.autoconfigure.thymeleaf.ThymeleafAutoConfiguration$DefaultTemplateResolverConfiguration] Cannot <span style="color: rgba(0, 0, 255, 1)">find</span> template location: classpath:/templates/<span style="color: rgba(0, 0, 0, 1)"> (please add some templates or check your Thymeleaf configuration)
; }9 ?1 K; m* n7 o0 ~webapp busybox </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">54.377</span> [INFO ] [main] [org.apache.coyote.http11.Http11NioProtocol] Starting ProtocolHandler [<span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">http-nio-4567</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)">]
- F, `% @/ k, u% E( vwebapp busybox </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">54.481</span> [INFO ] [main] [org.springframework.boot.web.embedded.tomcat.TomcatWebServer] Tomcat started on port(s): <span style="color: rgba(128, 0, 128, 1)">4567</span> (http) with context path <span style="color: rgba(128, 0, 0, 1)">''</span><span style="color: rgba(0, 0, 0, 1)">5 U6 S( K) a9 l8 A9 I& R) ?
webapp busybox </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">54.509</span> [INFO ] [main] [org.demo.webapp.todolist.TodoListApplication] Started TodoListApplication <span style="color: rgba(0, 0, 255, 1)">in</span> <span style="color: rgba(128, 0, 128, 1)">6.235</span> seconds (JVM running <span style="color: rgba(0, 0, 255, 1)">for</span> <span style="color: rgba(128, 0, 128, 1)">8.074</span><span style="color: rgba(0, 0, 0, 1)">)
; z! y) _3 V* Y- a# _6 N# |$ g5 vwebapp webapp
7 W" k9 T. p! L/ cwebapp webapp   .   ____          _            __ _ _1 I5 ?9 a0 R0 X6 h
webapp webapp  </span>/\\ / ___<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">_ __ _ _(_)_ __  __ _ \ \ \ \</span>2 E- ?8 j+ H) }
webapp webapp ( ( )\___ | <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">_ | </span><span style="color: rgba(128, 0, 0, 1)">'</span>_| | <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">_ \/ _` | \ \ \ \</span>
' I- t! t$ f5 z; u3 i9 P' q$ J7 o' }webapp webapp  \\/  ___)| |_)| | | | | || (_| |<span style="color: rgba(0, 0, 0, 1)">  ) ) ) )1 l7 z' i: C5 h' R* t: o& n
webapp webapp   </span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">  |____| .__|_| |_|_| |_\__, | / / / /</span>" \+ d8 d0 P/ \! r8 m7 Y
webapp webapp  =========|_|==============|___/=/_/_/_/<span style="color: rgba(0, 0, 0, 1)">
7 F8 K( {9 M) O, F+ pwebapp webapp  :: Spring Boot ::                (v2.</span><span style="color: rgba(128, 0, 128, 1)">4.2</span><span style="color: rgba(0, 0, 0, 1)">)+ E! V) ^# c! H4 D) z" |+ _
webapp webapp+ k' `; j( t5 g* R
webapp webapp </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">50.124</span> [INFO ] [main] [org.demo.webapp.todolist.TodoListApplication] Starting TodoListApplication v1.<span style="color: rgba(128, 0, 128, 1)">0</span>-SNAPSHOT using Java <span style="color: rgba(128, 0, 128, 1)">1.8</span>.0_111 on webapp with PID <span style="color: rgba(128, 0, 128, 1)">1</span> (/opt/soft/webapp.jar started by root <span style="color: rgba(0, 0, 255, 1)">in</span> /opt/<span style="color: rgba(0, 0, 0, 1)">soft)/ ]# z' a- u  f& _4 J
webapp webapp </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">50.165</span><span style="color: rgba(0, 0, 0, 1)"> [INFO ] [main] [org.demo.webapp.todolist.TodoListApplication] No active profile set, falling back to default profiles: default# _: b! M# m6 N- w2 X) K- P0 u
webapp webapp </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">53.158</span> [INFO ] [main] [org.springframework.boot.web.embedded.tomcat.TomcatWebServer] Tomcat initialized with port(s): <span style="color: rgba(128, 0, 128, 1)">4567</span><span style="color: rgba(0, 0, 0, 1)"> (http)
0 }9 c' [6 H" [webapp webapp </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">53.197</span> [INFO ] [main] [org.apache.coyote.http11.Http11NioProtocol] Initializing ProtocolHandler [<span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">http-nio-4567</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)">]
; x/ C. M/ W  g1 H& W$ J. ]webapp webapp </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">53.200</span><span style="color: rgba(0, 0, 0, 1)"> [INFO ] [main] [org.apache.catalina.core.StandardService] Starting service [Tomcat]
; M  [3 }0 {! M' |9 ~webapp webapp </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">53.201</span> [INFO ] [main] [org.apache.catalina.core.StandardEngine] Starting Servlet engine: [Apache Tomcat/<span style="color: rgba(128, 0, 128, 1)">9.0</span>.<span style="color: rgba(128, 0, 128, 1)">41</span><span style="color: rgba(0, 0, 0, 1)">]
: {5 ]0 n- ~1 K* h+ t/ @webapp webapp </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">53.324</span> [INFO ] [main] [org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/<span style="color: rgba(0, 0, 0, 1)">]] Initializing Spring embedded WebApplicationContext; ~$ o1 x* `) L0 o. u
webapp webapp </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">53.325</span> [INFO ] [main] [org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext] Root WebApplicationContext: initialization completed <span style="color: rgba(0, 0, 255, 1)">in</span> <span style="color: rgba(128, 0, 128, 1)">2952</span><span style="color: rgba(0, 0, 0, 1)"> ms+ }( B7 Y2 d+ F0 }% Z& {
webapp webapp </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">53.801</span> [INFO ] [main] [org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor] Initializing ExecutorService <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">applicationTaskExecutor</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">
0 x1 Y8 j4 h" |webapp webapp </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">54.264</span> [WARN ] [main] [org.springframework.boot.autoconfigure.thymeleaf.ThymeleafAutoConfiguration$DefaultTemplateResolverConfiguration] Cannot <span style="color: rgba(0, 0, 255, 1)">find</span> template location: classpath:/templates/<span style="color: rgba(0, 0, 0, 1)"> (please add some templates or check your Thymeleaf configuration)- b7 P- H9 H# G# x; p! B* B! ]
webapp webapp </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">54.377</span> [INFO ] [main] [org.apache.coyote.http11.Http11NioProtocol] Starting ProtocolHandler [<span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">http-nio-4567</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)">]. K! {" J% |' [+ ^5 I
webapp webapp </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">54.481</span> [INFO ] [main] [org.springframework.boot.web.embedded.tomcat.TomcatWebServer] Tomcat started on port(s): <span style="color: rgba(128, 0, 128, 1)">4567</span> (http) with context path <span style="color: rgba(128, 0, 0, 1)">''</span><span style="color: rgba(0, 0, 0, 1)">
( w/ E( V; y' r# Xwebapp webapp </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">54.509</span> [INFO ] [main] [org.demo.webapp.todolist.TodoListApplication] Started TodoListApplication <span style="color: rgba(0, 0, 255, 1)">in</span> <span style="color: rgba(128, 0, 128, 1)">6.235</span> seconds (JVM running <span style="color: rgba(0, 0, 255, 1)">for</span> <span style="color: rgba(128, 0, 128, 1)">8.074</span>)</pre>0 T; b: w! [' Z* |6 M& Q
</div>
# w( x/ j& S: c& y<p>&nbsp;</p>
+ r/ J3 g8 y; d- X% o
回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|飞雪团队

GMT+8, 2025-9-16 02:25 , Processed in 0.071588 second(s), 21 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表