飞雪团队

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

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

[复制链接]

7508

主题

7596

帖子

2万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
24854
发表于 2022-2-12 14:35:42 | 显示全部楼层 |阅读模式
9 j! ?( ]9 s/ K- P$ `& `
<p>kubectl作为我们主要的操作K8S的工具,其具备非常丰富的功能,但是如果不经过打磨,使用起来还是存在诸多不便,今天我们来看看如何将我们的kubectl打磨的更加易用。</p>! o: g$ f; a1 s
<p>&nbsp;</p>
8 o) s* V8 X3 I) W+ A( r, T<p>一、命令自动补全</p>* Q4 T# r6 [' [6 J! O
<p>kubectl中提供非常多的命令,如果每一次都要手动一个字符一个字符的敲未免太累了,那么如何配置自动补全呢?这里以ubuntu系统为例:</p>
" e6 y4 m) H; Y# j<p>1、安装auto-completion工具</p>0 q# X, L' H+ ~1 W( O
<div class="cnblogs_code">8 c7 a: t% x" q/ {, P9 _; I& b' M
<pre>$ <span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> apt update
, L1 \2 D- v9 m6 ~1 oHit:</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>9 M8 B" a+ F* @$ A7 F
Hit:<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>( z/ l" o8 s9 s) t% }
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>+ b. u4 w- b- i; M2 G" m9 K4 u
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>- Y6 b  y, s1 d. ^1 h# o+ H
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>
" d/ R& ?# ?; c<span style="color: rgba(0, 0, 0, 1)">Reading package lists... Done
  ?$ E3 a+ C  w5 Z4 @7 O$ B* ]Building dependency tree) J! g2 P" |8 ]9 U/ d/ H8 C
Reading state information... Done9 Q7 _& x' S# _8 A0 E! T5 y* M
</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.
' Q$ Z6 }* Y3 @7 N& a! V1 `7 c$ </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)">completion# }$ i3 S/ T& {4 C
Reading package lists... Done
- ~( S2 M5 p* Y9 mBuilding dependency tree# e% P; U: a) d, Y- y& g
Reading state information... Done
( m0 E5 B" g! D" P0 J: Gbash</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).
# g6 p! f7 Q( A# N6 ~</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>1 ^( N2 a7 v' w' D% E% `
</div>/ {. X/ j4 Y$ n% a, g2 Z) ?0 l
<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>8 B% j& K' W% D- M. Y- O
<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>
+ N3 d8 u9 @! X" S+ N) b4 ?/ h<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>4 Q/ e$ t- g' Z1 R
<div class="cnblogs_code">
1 j7 y- Z3 ^& ^" ~+ k; |<pre>source &lt;<span style="color: rgba(0, 0, 0, 1)">(kubectl completion bash)
/ j' B  l/ j! t4 {</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>. L' Q) g" h7 J. p% u! V
</div>( [. d4 W* o* j0 q1 Q0 V& {, W
<p><strong>Zsh</strong>:</p>
9 y& r0 p9 ]4 x2 Y0 ^7 ^) w- o& ^. m<div class="cnblogs_code"># b7 D) }' Q5 ~" u) i
<pre>source &lt;<span style="color: rgba(0, 0, 0, 1)">(kubectl completion zsh)
6 v+ }$ S' `$ F4 _% x+ h, Y</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>  ~( h- O9 o. o+ i+ A9 N( b: ?
</div>
% D/ l# T/ t+ M/ y, c<p>配置后就可以通过Tab键自动补全命令啦!</p># C3 k; M8 Z* i# T7 t
<p>&nbsp;</p>! b; N# W2 e  J+ b9 r- R' ^
<p>二、配置kubectl别名</p>
3 c( A( t, q6 H7 b, c<p>我们可以通过设置别名简化kubectl命令,编辑.bashrc文件,添加如下内容:</p>
8 K0 L6 ^, }" W4 Y1 T$ `<div class="cnblogs_code">
( a9 k. N! |6 F; K4 q+ Y5 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)">
7 A5 E, u# ~  Palias 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)">4 D2 i5 N4 j6 f! ]7 W" u
alias 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)">8 I0 r0 H& m! c* k3 V1 {; i: |
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)">1 h3 V+ ]! l5 B" i" |/ q7 C
alias 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)">
! E/ s" `% W/ d0 |$ O3 ?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)">( T, r6 S4 w  e3 u! D$ R
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>
! w/ w. `$ x: o/ s% t9 j7 ]- }' ~</div>! s5 a0 w7 _* }; q% f$ \; Z
<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>  Q4 I6 [9 q# v5 K$ `
<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>
: D( {9 {) u) h7 W! S<div class="cnblogs_code">1 K. \. q( d, E& v( I7 h: P
<pre>$ <span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> ka webapp_pod.yaml- K9 M  j5 e  T) @
pod</span>/<span style="color: rgba(0, 0, 0, 1)">webapp created1 Y* W( k/ ~2 v5 h6 |
$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> kg pods' n7 l! u0 F9 R. d4 D; o% t/ p
NAME     READY   STATUS              RESTARTS   AGE
, a8 p, N- w2 n( uwebapp   </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)">          7s
1 v0 F& R' R3 ^0 p$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> kd pod webapp% G" K$ g* X9 K, B
Name:         webapp
( ^3 h, A1 V: yNamespace:    default! E& F5 C$ @* M, U, P% C3 m$ k
Priority:     </span><span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">
9 y3 n6 F) q; A# U8 B2 BNode:         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)">+ t. C  ]2 R( n% [: `- n5 s
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)">" Q2 U' h! ]6 r5 M3 M6 F2 Y- i. }
Labels:       app</span>=<span style="color: rgba(0, 0, 0, 1)">webapp
- u9 H8 {' v3 B# sAnnotations:  </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">, G7 z0 o1 V6 |
Status:       Running
( r) L$ b  b9 z7 ^+ IIP:           </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)">
% Y* L' W/ U' F9 B2 e- M8 i% F( ?IPs:
8 Q- M! U7 {2 p3 ?/ x  L/ ~  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)">% L" g! E  D) ]. E8 @- w
Containers:
6 |. j4 X+ I3 Q$ W1 c4 ^  webapp:/ L. U  f( c- m; b4 X% _
    Container ID:   docker:</span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">d9ddf9dd47de12b53f2119bf75df6706bee2e7711509638ad52adc9addeda704</span>2 k' G" B/ S" O( {. ^6 W" h
    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)">
& v3 [, ^7 s* }3 `, s5 E* \    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>2 R" K1 T0 Z" F+ v" k% p3 Q
    Port:           <span style="color: rgba(128, 0, 128, 1)">5000</span>/<span style="color: rgba(0, 0, 0, 1)">TCP
  V- g' T& `% z! x3 B. l    Host Port:      </span><span style="color: rgba(128, 0, 128, 1)">0</span>/<span style="color: rgba(0, 0, 0, 1)">TCP
5 y7 ^7 R( \5 V6 L* E5 a" ^    State:          Running
3 z3 g2 Q! v8 A      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)">" \% F; m, B1 F( g9 t: G% Y
    Ready:          True
: D3 E( O2 h, y. a. I, b    Restart Count:  </span><span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">' U$ s  G/ ?4 v8 b
    Environment:    </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">
6 P$ q0 k9 x# t% S5 K# D    Mounts:
8 l  w: n% g- m3 W( U' n      </span>/tmp from webapp-<span style="color: rgba(0, 0, 0, 1)">logs (rw)  `4 h; b* ^7 y% {
      </span>/var/run/secrets/kubernetes.io/serviceaccount from default-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h (ro)
- V+ K: g+ B- n& t5 m4 Q. k  busybox:8 \4 c& S5 ~& W8 E" b- F& `8 m' H6 V5 B
    Container ID:  docker:</span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">6a6a35a628a782fc643af3dd49986bbc77c23de1ae4726bc521c77f61abbbf5d</span>
1 a/ e* d7 q: f/ l# z<span style="color: rgba(0, 0, 0, 1)">    Image:         busybox5 f% F+ H9 P) f# [! c# n
    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>
# m/ k) u8 P! g" s- {8 h, n    Port:          &lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">
8 w2 H5 s& _- z9 ]5 n    Host Port:     </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">
2 `/ c6 _/ M9 H    Command:$ o7 K: I3 W" s; f6 f' f% K$ `/ W/ @
      </span><span style="color: rgba(0, 0, 255, 1)">sh</span># `# l8 [3 d& c  f
      -<span style="color: rgba(0, 0, 0, 1)">c
3 @. C$ f0 A# F: I8 c' ^      </span><span style="color: rgba(0, 0, 255, 1)">tail</span> -f /logs/<span style="color: rgba(0, 0, 0, 1)">log.out
. S5 f# Y( x3 F3 w( f    State:          Running
1 I8 o! v  }7 I* K/ X2 Z2 T$ s2 |: s      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)">" R1 W0 Z9 F/ |
    Ready:          True9 Q/ s* }; r  s" P$ L) p# o
    Restart Count:  </span><span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">2 n" \% P$ w6 f; Y  i7 ~: A
    Environment:    </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)"># l( Q6 g1 @7 w) L" D6 w
    Mounts:: t: q; f) f" X% b; x* b8 U7 W: Z
      </span>/logs from webapp-<span style="color: rgba(0, 0, 0, 1)">logs (rw)& a5 O1 j$ z) k$ _  R
      </span>/var/run/secrets/kubernetes.io/serviceaccount from default-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h (ro)1 w) J+ a( x5 k3 m" T
Conditions:
$ i# N+ I, M3 _% ^/ R' O2 u! G, e  Type              Status+ q* E& H/ Q2 B3 |' E$ W
  Initialized       True
- D- L2 ~/ F( q' x+ P  Ready             True
( G, f6 h  j0 Q5 `  ContainersReady   True$ g, A  k/ v3 ], h6 I
  PodScheduled      True
3 }+ F8 e& ?8 m+ XVolumes:. Y3 P, w/ k! D' U! r6 }4 {
  webapp</span>-<span style="color: rgba(0, 0, 0, 1)">logs:9 X) f- x* |( \! }: U
    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>2 h0 m1 [9 v; R: T0 V( R
<span style="color: rgba(0, 0, 0, 1)">    Medium:
* ~& l: z7 @0 F; u' F7 C6 p- H) Q    SizeLimit:  </span>&lt;unset&gt;<span style="color: rgba(0, 0, 0, 1)">
8 R/ n: q6 d; ?: T/ L( b  default</span>-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h:, O/ T; a9 P$ v: d% J# b
    Type:        Secret (a volume populated by a Secret)
5 ?: O( F- l+ K5 h; ?) L. G, j    SecretName:  default</span>-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h
% @5 X5 ?# S$ r$ Q5 P1 \! L+ R$ Z    Optional:    </span><span style="color: rgba(0, 0, 255, 1)">false</span><span style="color: rgba(0, 0, 0, 1)">
2 A: G. c, v7 ?% U+ |% z5 ZQoS Class:       BestEffort  K2 |% Z! o3 c
Node</span>-Selectors:  &lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">* c' z2 }, i4 w2 H  }
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$ a+ m: V6 V+ y( q+ h4 B
                 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" ?& l0 h# }! U4 @( y' s+ f+ n
Events:# H2 ?; V0 @* `* I! l. M  r
  Type    Reason     Age    From               Message
: h7 B, y0 g- N1 T  </span>----    ------     ----   ----               -------<span style="color: rgba(0, 0, 0, 1)">
! A$ @7 Q7 U# [! I/ G( v8 \  Normal  Scheduled  2m23s  default</span>-scheduler  Successfully assigned default/<span style="color: rgba(0, 0, 0, 1)">webapp to ayato
1 u/ p8 |8 f' S3 L: z3 U  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 machine6 Y$ f! {! `, Z5 K& `
  Normal  Created    2m21s  kubelet            Created container webapp, A# Q. D4 P9 b" n4 n; E; z8 ?
  Normal  Started    2m21s  kubelet            Started container webapp9 K2 U7 P) r  A( w3 ~
  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 U( s# Z. ^6 O4 D9 Q9 y8 |0 y1 F  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* s6 q) i6 }  j4 D: \
  Normal  Created    15s    kubelet            Created container busybox( U* N7 y, x6 I# R8 X9 W
  Normal  Started    14s    kubelet            Started container busybox</span></pre>
  B6 a' i& ^, r* n2 o% e6 g& ]& c0 M</div>
- F3 [# p/ j) a9 [: |8 X# O" i<p>真的是飞一般的感觉!!!</p>
; O( R; J0 J) g4 u8 }<p>&nbsp;</p>
! L' E/ C% z" E2 G1 F( n" B7 C, ?<p>三、Context和Namespace切换</p>
4 J. m) a8 @5 \2 J- Y) d2 G- S<p>我们在公司的容器平台上使用kubectl时,经常需要切换context和namespace,导致命令非常繁琐,那有没有简便的方式呢?—— kubectx</p>
( x) g, _" U) p/ w/ O<p>kubectx安装</p>9 X+ w, _$ ?- _* e  R5 V7 G
<div class="cnblogs_code">- x7 h5 A' e. N7 r% t# t& C
<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>: a( H) _3 f4 S3 S1 |  |
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)">...! r, i' P5 q7 s. s8 [
remote: 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)">.( Z) J# @9 h! @, E/ {
remote: 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)">.
8 `5 U' s" M, L. f2 B& L0 J' W" tremote: 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)">.( r/ y: Y5 y7 C& C
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)">
' Z# F, p2 ?5 X3 x9 eReceiving 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( w, I) U+ q; K( 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)">.
% b/ C) Q8 V/ A5 n0 O& T6 W$ </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)">ns7 Z" p9 ]! |* c
$ </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>6 ?3 n& j& f) p' K6 E9 {
</div>
( v- E4 q- q, Q: d: `" \( q<p>我们来看一下效果:</p>
5 j* j7 g4 z0 w6 i<div class="cnblogs_code">
: ?2 Z0 v# v1 y; U! Q( j<pre>$ <span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ctx: f! U; W5 r: \2 E
minikube' q) @- V  N/ y) e
$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ctx minikube6 I+ m/ H8 [# V( T$ f
Switched 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)">.
; X4 Y: x9 }- ]8 y- Z5 [$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ns9 [' \3 o8 b; \1 R; t8 G( p
default
0 _- {5 U7 S5 P# Skube</span>-node-<span style="color: rgba(0, 0, 0, 1)">lease3 P4 l) r- e7 z, a2 K" G
kube</span>-<span style="color: rgba(0, 0, 0, 1)">public% u5 ^, S' |; j) s
kube</span>-<span style="color: rgba(0, 0, 0, 1)">system
6 o1 x. g1 g" g7 B9 a- Skubernetes</span>-<span style="color: rgba(0, 0, 0, 1)">dashboard
9 R/ l3 D! n# y5 \9 y: k$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span> k ns kube-<span style="color: rgba(0, 0, 0, 1)">public
; ^5 r& x; O5 [& A. DContext </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.
  I( T4 t8 O2 y" m* A) \Active 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)">.
/ n  i6 z1 z  m3 t9 ~$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ns default) _5 _- E! L0 y- X  K
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.
# J5 H% ~& E7 o& I( w0 zActive 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>
7 v. F6 m+ A: s% n# A</div>
% o) D: g* c, e2 h/ _# O5 Y& g2 _<p>&nbsp;</p>$ K1 p  K7 }7 P. M; G
<p>四、跟踪查看多个Pod的日志</p>3 d3 r1 A$ X; {9 F+ _
<p>我们一般使用kubectl logs命令查看Pod日志,但是它不能通过-f参数同时跟踪查看多个Pod日志,这就不方便了,毕竟实际生产环境中每个服务都会有多个Pod,这时我们可以使用stern这个工具,它具备如下能力:</p>1 ~6 s, g" |0 ?8 t( Z2 ]
<ul class="list-paddingleft-2">
7 H# H+ p6 G, V+ t0 s9 D$ W<li>
. \8 N' u6 K$ S# t1 q<p>允许使用正则表达式来选择需要查看的PodName</p>
5 _* D# ]  z; U, H</li>
$ U8 ^9 h( |( I# [' R0 D5 e<li>6 L0 i7 A2 ?# y  V5 ~' K) p( `' j
<p>为不同 Pod 的日志展示不同的颜色</p>; r" c  D- o3 W! ]9 \, `# X
</li>. j7 b) N8 c9 m" t" z
<li>
. u1 p8 m. ]/ u$ x8 k<p>跟踪日志过程中假如有符合规则的新 Pod 被创建, 那么会自动添加到输出中</p>; `6 E- Q* e1 N& N
</li>% N- Q0 g" h8 l8 S
</ul>
/ }6 c# y! l9 k<p>首先安装stern(下载stern时可能较慢可以多试几次):</p>
4 ~" B5 m0 G/ b3 L! T( G; V, w<div class="cnblogs_code">) p% I$ ^0 \' ^6 r$ y+ u, \) l
<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>/ _# E' [. o' o* |
<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>$ p- q# R8 l: L$ x
<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>- E! s2 }$ e; k
</div>
( S* y; U* y& d$ g7 m3 r/ I8 C4 i<p>安装完毕后让我一起感受一下stern的魅力吧,我的Pod里面有两个容器:webapp和busybox,如果使用kubectl logs 还得指定具体的容器,而使用stern就没有这样的限制。</p>
$ N. N8 _8 @( [  w% Z1 o<div class="cnblogs_code">1 D! U. u1 t' _* S
<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)"> .
* @* Y. D: f# i4 T0 W</span>+<span style="color: rgba(0, 0, 0, 1)"> webapp › busybox/ [! x4 _' J% x: K* |
</span>+<span style="color: rgba(0, 0, 0, 1)"> webapp › webapp
$ E( R5 A9 S5 i5 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.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)">]
; }9 n4 {9 L( L" ~, p. |* l9 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.200</span><span style="color: rgba(0, 0, 0, 1)"> [INFO ] [main] [org.apache.catalina.core.StandardService] Starting service [Tomcat]
3 c: B$ c' o+ I* @8 u# o! Hwebapp 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% u; x4 w, Y) D
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.324</span> [INFO ] [main] [org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/<span style="color: rgba(0, 0, 0, 1)">]] Initializing Spring embedded WebApplicationContext
0 q$ p: l' `" S: m/ 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
6 y  G4 j' @) G/ rwebapp 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)">$ E5 j! p$ Z2 Z1 L
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)4 J! z0 Q# p* _, O# E
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)">]
, D/ E, S+ ]1 D2 {8 Swebapp 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)">
. x1 S4 u3 q$ ], D& Rwebapp 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)">)& o& F8 o" G5 K
webapp webapp' _0 Z4 O) k+ X9 J* c$ _  y
webapp webapp   .   ____          _            __ _ _
2 Y/ Q+ o2 n; [  r6 H% @webapp webapp  </span>/\\ / ___<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">_ __ _ _(_)_ __  __ _ \ \ \ \</span>
5 D) s+ m8 S' C' K* J! g+ {7 Kwebapp 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>
# K. j: D2 v3 p: hwebapp webapp  \\/  ___)| |_)| | | | | || (_| |<span style="color: rgba(0, 0, 0, 1)">  ) ) ) )# v9 u9 }8 o( H6 k( M% k' @8 T
webapp webapp   </span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">  |____| .__|_| |_|_| |_\__, | / / / /</span>! y7 [5 S9 O! E+ J/ P' A# m, h
webapp webapp  =========|_|==============|___/=/_/_/_/<span style="color: rgba(0, 0, 0, 1)">
: G. o1 W4 ?8 ]% k" E" J- Bwebapp webapp  :: Spring Boot ::                (v2.</span><span style="color: rgba(128, 0, 128, 1)">4.2</span><span style="color: rgba(0, 0, 0, 1)">)% b! p5 d# X' a. G7 ?0 r
webapp webapp
# Y' d9 Y6 ]& O# k; f5 _% F! iwebapp 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)9 t4 z) p% z4 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)">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
1 Y6 P, H3 @8 qwebapp 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)# k* |1 z. f. y7 C
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)">]" b/ x) o! `7 A* n( S
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]5 x' o1 e' n+ ?! `& l6 @# q
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)">]
: @: G2 X8 O* E7 k0 Gwebapp 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
+ O& o  N* m9 f' Hwebapp 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)"> ms4 r; a* ~1 [0 n
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)">
* n5 U0 H6 a1 g' g* F: q0 ?- Ywebapp 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)
( S. _2 |0 `/ V8 x8 Vwebapp 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)">]2 x6 c1 m+ s" G2 C3 V- A" 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)">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)">! j/ n+ W0 e. c* z4 o
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.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>2 l5 i  c2 ]4 W; j+ ^7 m& e  j* w3 I2 r
</div>+ J6 n2 T3 |  x6 y9 {
<p>&nbsp;</p>
9 L+ [2 C2 x7 i& p, d5 R) u4 ~
回复

使用道具 举报

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

本版积分规则

手机版|飞雪团队

GMT+8, 2025-9-9 17:58 , Processed in 0.118740 second(s), 22 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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