飞雪团队

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

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

[复制链接]

6865

主题

6953

帖子

2万

积分

管理员

Rank: 9Rank: 9Rank: 9

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

- ~5 L. V  Z* ]. s<p>kubectl作为我们主要的操作K8S的工具,其具备非常丰富的功能,但是如果不经过打磨,使用起来还是存在诸多不便,今天我们来看看如何将我们的kubectl打磨的更加易用。</p>
. _2 h+ X. J" o6 A<p>&nbsp;</p>
2 E' n3 o; v+ c! a7 G5 o4 Z1 U<p>一、命令自动补全</p>- I6 @* p$ S1 O, s& }2 k  \; u# z5 f
<p>kubectl中提供非常多的命令,如果每一次都要手动一个字符一个字符的敲未免太累了,那么如何配置自动补全呢?这里以ubuntu系统为例:</p>
" p. W2 A3 o# [9 K" k<p>1、安装auto-completion工具</p>
% Q/ Z/ {6 v+ B! ^' e) l<div class="cnblogs_code">  U( i9 x' A' c8 _
<pre>$ <span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> apt update" O' ]/ ], V5 P
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>* N2 W& h" r! ^  I4 @5 l, w  J
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>
- y6 [, ~. Q2 x) V- Y( ^6 _3 m+ cHit:<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>9 R9 u) A, I& q" n" m- I
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>2 b: `0 \) L! k; c
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>
" _. T; p- j, T& X" [) P<span style="color: rgba(0, 0, 0, 1)">Reading package lists... Done
; Z0 \+ {4 s$ C7 i5 J+ ~5 NBuilding dependency tree: s+ R- w& J. r  e
Reading state information... Done
# }. ^9 `+ n/ v) E4 d8 w8 Q</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.
/ p8 T; P: d  ~/ R: [( I& 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)">completion
% }$ z! S0 p/ q2 kReading package lists... Done! C* I/ ~% ^' y5 G- I* p: @
Building dependency tree' E, C% e5 o" }. Z" z% w3 E
Reading state information... Done
# }; _0 J/ e; ?) `5 @; D) n( I7 K1 e4 E" C1 _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).
" B9 m. ]% S  `, S</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>: C6 S; K$ r% M
</div>0 O) Z9 z) G  \/ C7 f. R7 }
<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>6 U* Q# F" z( |& `
<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>
! Y; c! k+ B* p  ]8 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>
: p  Z2 V; f7 L+ P* p8 D<div class="cnblogs_code">0 f" @" h; Y1 b) y
<pre>source &lt;<span style="color: rgba(0, 0, 0, 1)">(kubectl completion bash)
& `2 G, c9 ^( c" |</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>* z; j5 W  n6 X
</div>
- z0 d% O* k: H, }<p><strong>Zsh</strong>:</p>
, z4 Z3 W* m4 ^, o, b<div class="cnblogs_code">- [; s/ K+ c7 [1 V% _4 z
<pre>source &lt;<span style="color: rgba(0, 0, 0, 1)">(kubectl completion zsh)
% i+ x9 B1 F  B( Y( k% e</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>  p6 c( _5 R% s" `% j+ K' H
</div>
, c$ `3 ]( D" \, c<p>配置后就可以通过Tab键自动补全命令啦!</p>
. v9 u* |5 M2 u<p>&nbsp;</p>& m" r$ S0 V2 f" J
<p>二、配置kubectl别名</p>
' k* H; ?2 o+ \0 v6 |<p>我们可以通过设置别名简化kubectl命令,编辑.bashrc文件,添加如下内容:</p>9 ]5 r4 u' o" S' Z
<div class="cnblogs_code">7 K' s5 [" i5 E* \5 l$ 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)">$ d$ u5 E9 C1 E5 q# M0 B4 }
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)">
, r0 ^9 |8 e7 ^* P9 n/ Valias 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)">
& L: W- S; ~0 \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)">" \% B6 v& g" _7 G) O' l
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)">' r. d" [  t( T3 u9 p% n
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)">
+ g0 p+ Q, Q! u3 f( E+ p3 @, valias 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>2 S! J3 E* @4 k6 u  W6 E5 [; }" Q
</div>  x5 S- H5 v* o  I& H
<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>, {% q# c8 ^2 f0 F; x3 F4 b
<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>8 f+ a' n* f! z$ c
<div class="cnblogs_code">
8 s2 a/ x, o  l% q8 }5 w2 ~<pre>$ <span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> ka webapp_pod.yaml
4 K! R1 T8 |  ~; Kpod</span>/<span style="color: rgba(0, 0, 0, 1)">webapp created
5 I: h/ i$ q+ o7 e# {' L  D$ b$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> kg pods
  g; N" N$ r7 m1 e" [+ wNAME     READY   STATUS              RESTARTS   AGE; ]$ x" s: e- V# B4 J8 t2 c* m% R
webapp   </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)">          7s4 A, ^! E4 H5 ^, d2 j4 G# J
$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> kd pod webapp; b. C  r# M1 ?8 I" Z# `
Name:         webapp! [4 ~% J( S9 l
Namespace:    default- H+ t3 f4 S* n7 _3 @! |$ W* P% z5 k+ ?
Priority:     </span><span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">
0 e1 P; l0 e$ K5 MNode:         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)">
& y+ e8 N5 b6 m! Z3 s0 MStart 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)">- S. k) b: `5 ]' ]' i, S" T1 D. }# \
Labels:       app</span>=<span style="color: rgba(0, 0, 0, 1)">webapp
' x! A2 f8 c7 lAnnotations:  </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">3 p  l( G' t- W# A& }* M2 J/ W% ?
Status:       Running, _( L, ]2 m- E! _, {( |7 J
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)">
: L9 j( o# s) ]  l& C; t: p' A( GIPs:, \9 f' f1 g, V
  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)">
, e0 G8 V7 e0 X6 m" \  MContainers:% P; f8 W' e( e% |3 F
  webapp:' [3 Z% R/ V% U, B$ l
    Container ID:   docker:</span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">d9ddf9dd47de12b53f2119bf75df6706bee2e7711509638ad52adc9addeda704</span>
! j: {7 Z- @- K- K# m% Z    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)">! a. d% A$ ?! i0 M! z  d3 u
    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>
, A7 C4 e8 q. h2 F    Port:           <span style="color: rgba(128, 0, 128, 1)">5000</span>/<span style="color: rgba(0, 0, 0, 1)">TCP
2 x: N& Q, G1 J, h& B' _% K' N    Host Port:      </span><span style="color: rgba(128, 0, 128, 1)">0</span>/<span style="color: rgba(0, 0, 0, 1)">TCP
$ Y; t, T& y0 t) C    State:          Running
. k$ n/ U2 {5 \6 u      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)">9 S7 z" f3 Q- R
    Ready:          True
4 E. `  F. y3 b; e    Restart Count:  </span><span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">; t: N$ v6 K9 X' v  a
    Environment:    </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">
/ z' M9 }# a( B3 o4 t    Mounts:, Y3 s9 \( _. F8 O! k4 d) w" {+ {
      </span>/tmp from webapp-<span style="color: rgba(0, 0, 0, 1)">logs (rw)/ r  ]  e, @  Q2 |, j! }% V& q) h
      </span>/var/run/secrets/kubernetes.io/serviceaccount from default-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h (ro)
8 B. N  I; |, ]5 @/ u, w' ?  busybox:0 K# ?0 V2 d1 I  p/ [: v, J+ _  |3 q. O) y
    Container ID:  docker:</span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">6a6a35a628a782fc643af3dd49986bbc77c23de1ae4726bc521c77f61abbbf5d</span># ~" p" G& h# L( ?8 s% G
<span style="color: rgba(0, 0, 0, 1)">    Image:         busybox
8 A# d8 Y1 J) d& W: X    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>
0 S6 w* V& {3 f4 b3 b+ `& A6 {8 I    Port:          &lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">8 l' R/ Q1 I& h4 a
    Host Port:     </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">4 _* ?9 G  G: m) O1 M. d
    Command:/ l, T$ K0 ]% W3 ?
      </span><span style="color: rgba(0, 0, 255, 1)">sh</span>
- J3 n6 @- l8 b6 b2 D      -<span style="color: rgba(0, 0, 0, 1)">c  }& ]3 F9 {4 F2 `+ ]7 J! O
      </span><span style="color: rgba(0, 0, 255, 1)">tail</span> -f /logs/<span style="color: rgba(0, 0, 0, 1)">log.out  |9 x0 i6 I$ f' K) q& w9 x$ X% B7 u
    State:          Running
1 E/ w& A% y  j2 Z5 N% K  E      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)">5 v# K: y4 j9 y4 ~
    Ready:          True
! R8 e1 T/ H& n. Y3 U& }    Restart Count:  </span><span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">7 V9 i% I! S+ N. C) O# x! W/ _1 p
    Environment:    </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">
) U7 [8 Y' S" `0 S    Mounts:: G/ @+ h! W4 D& U$ e3 {
      </span>/logs from webapp-<span style="color: rgba(0, 0, 0, 1)">logs (rw)! K4 D% Q) l( ]% d, E
      </span>/var/run/secrets/kubernetes.io/serviceaccount from default-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h (ro)% t; a( a1 z3 e# K9 e& |, o/ W4 U: t1 s
Conditions:( `% u, n1 S3 l1 b1 G6 `/ ^6 E( Q
  Type              Status
+ a7 b, q7 Z& |% |3 y  Initialized       True; m# i9 j; G2 F6 T5 x  F6 K. Z
  Ready             True
9 K% @8 g7 y: t% y+ o  ContainersReady   True- s4 M2 {9 I8 c
  PodScheduled      True
. ]8 N, F5 h& X( I( ]/ x: X0 vVolumes:
- F: A+ g% i  B0 q% ^  webapp</span>-<span style="color: rgba(0, 0, 0, 1)">logs:
1 d( [$ ~0 Q- ?% G5 V! e  v5 E    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>
( Y) b* R; r/ ^4 ]3 q5 [  d4 l# T<span style="color: rgba(0, 0, 0, 1)">    Medium:
$ l: f4 K; F2 }# o& o9 Z; @9 l* j    SizeLimit:  </span>&lt;unset&gt;<span style="color: rgba(0, 0, 0, 1)">0 D5 U! r$ z3 v  L6 R: S. `1 Z
  default</span>-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h:
) J# j( w& _- x+ s  I    Type:        Secret (a volume populated by a Secret)+ P+ H+ A* `/ Z# c/ d
    SecretName:  default</span>-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h4 R5 Q+ v- y6 m" i4 U  @
    Optional:    </span><span style="color: rgba(0, 0, 255, 1)">false</span><span style="color: rgba(0, 0, 0, 1)">
% l* m$ P) s0 t/ v. M: p0 p( VQoS Class:       BestEffort/ W8 [3 z+ Y( r. O
Node</span>-Selectors:  &lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">
; j: x" x# m/ H4 Q. K6 RTolerations:     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
, A7 c" e8 v( k8 @- L9 d                 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
: x7 h+ F9 x3 m# W- y7 m9 L+ R% S) [Events:! ?( N' j6 o& r
  Type    Reason     Age    From               Message
/ E# L1 D" l/ P2 n& Z  </span>----    ------     ----   ----               -------<span style="color: rgba(0, 0, 0, 1)">& M6 b2 @! }. y- Y% ^$ v
  Normal  Scheduled  2m23s  default</span>-scheduler  Successfully assigned default/<span style="color: rgba(0, 0, 0, 1)">webapp to ayato
; ?! k. s( i1 x- z6 @2 b  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 machine4 o7 |+ k- K' n/ F" v4 n/ b3 R
  Normal  Created    2m21s  kubelet            Created container webapp; q: t. Z  V. z  M1 b5 r
  Normal  Started    2m21s  kubelet            Started container webapp
. a0 D+ m1 _8 g4 y  y6 |  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)">0 Z9 t' q, ?+ U* K
  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
, G9 v, f8 E( m- C& d; X. q, k3 |  Normal  Created    15s    kubelet            Created container busybox$ O% O6 F" M2 a& P) k
  Normal  Started    14s    kubelet            Started container busybox</span></pre>1 \/ @# g' ]/ P6 k) J4 Y! O: V" R
</div>) F/ W- b6 f1 V0 A- |  [4 [: J
<p>真的是飞一般的感觉!!!</p>
; o7 E  [: ^! V( a+ z$ q) U+ \<p>&nbsp;</p>" H4 C5 {- b5 s* N' G
<p>三、Context和Namespace切换</p>7 Z  W. n5 r/ F  c6 O
<p>我们在公司的容器平台上使用kubectl时,经常需要切换context和namespace,导致命令非常繁琐,那有没有简便的方式呢?—— kubectx</p>
# A2 `+ d& k/ y- y' A% I<p>kubectx安装</p>
& K  W- H; C! z8 I, o8 V) C; l<div class="cnblogs_code">0 g4 e# e1 U( g
<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>' G" M/ U# y: m" x
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)">...
- ]8 F+ P1 G3 I4 kremote: 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)">.
  c  }( v+ [5 V* ?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)">.2 P# i( E4 \' I
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)">.' }+ w, q9 L! R3 f9 M
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)">- I# h" i$ w. l9 J" q2 G
Receiving 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)">.
1 ]8 a8 a3 s* B* WResolving 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)">.4 H- y1 A$ n* k5 n4 x6 K% O
$ </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
5 A" f4 z4 f- b; i8 u8 i$ </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>7 B6 N- ^/ a7 f) m* z: P1 A9 g
</div>
- \2 F4 j$ U5 g8 }" d* m: s: x3 P<p>我们来看一下效果:</p>
! o! F* q$ d; N8 F<div class="cnblogs_code">7 k$ E: C3 |$ b* W: }0 T6 A1 n
<pre>$ <span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ctx
: U5 e4 h% _8 Y9 `$ g' vminikube
- s4 \! p1 I9 `' ~5 x$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ctx minikube
6 q4 E; e, v, L* g4 q; aSwitched 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)">.
/ k  z4 B2 J( c9 W$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ns
0 Z# b& n; A7 I( vdefault# L7 \! X- ~5 R/ x* {- F# P- b2 ~
kube</span>-node-<span style="color: rgba(0, 0, 0, 1)">lease2 h8 I: ?3 C" y2 f- C/ m
kube</span>-<span style="color: rgba(0, 0, 0, 1)">public+ m8 u* P# {6 l. I( l
kube</span>-<span style="color: rgba(0, 0, 0, 1)">system5 l7 I% k/ p. p! R- f. L
kubernetes</span>-<span style="color: rgba(0, 0, 0, 1)">dashboard) P  S. [+ J3 d4 ]
$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span> k ns kube-<span style="color: rgba(0, 0, 0, 1)">public: }/ f3 y& D' |. i! r
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.8 x. `5 M' p! p
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)">.
/ o# a3 |' U, |  i$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ns default
! s( y, U' `' m8 G/ o$ XContext </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.+ J7 X+ ~' E0 O& i# Q8 j3 F+ }) y
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>
& b$ n/ A* ]/ k2 r" D</div>
' a6 z# J4 ?8 s4 r4 j6 s. E. N<p>&nbsp;</p>' v9 Y! p& @" j( S' I* R
<p>四、跟踪查看多个Pod的日志</p>
; C% p/ P. }/ w<p>我们一般使用kubectl logs命令查看Pod日志,但是它不能通过-f参数同时跟踪查看多个Pod日志,这就不方便了,毕竟实际生产环境中每个服务都会有多个Pod,这时我们可以使用stern这个工具,它具备如下能力:</p>
  Q+ S+ P9 a3 n$ @* c<ul class="list-paddingleft-2">- o! i" Z0 P* \: C
<li>7 M6 _, Z' ^  W( _, O- @6 f# g
<p>允许使用正则表达式来选择需要查看的PodName</p>
3 m, b8 r" ~5 {- m: w</li>+ a6 `  g% a/ x( z, D1 e# G
<li>
4 ~! K/ N% [3 }3 k<p>为不同 Pod 的日志展示不同的颜色</p>5 \# H/ ~0 ^6 _2 ~" e
</li>
- P5 |+ r8 T5 G' q<li>: T4 E- _& K2 g( f0 H. u7 c
<p>跟踪日志过程中假如有符合规则的新 Pod 被创建, 那么会自动添加到输出中</p>
0 J5 U# y- u, R! K$ A* x. [. {</li>" u7 l+ ], Z; d* j
</ul>
+ D* S% m$ u" _. c* {, w<p>首先安装stern(下载stern时可能较慢可以多试几次):</p>
0 A- v6 j$ k* j0 b* ^<div class="cnblogs_code">
6 j. c' w& @+ P, ?8 U: Q) H, W<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>
8 L* \* T3 `( a+ G6 d<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>1 H5 q3 M6 Y- Y0 T
<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>
# Q6 }& R( o, [8 V; [" f</div>9 _$ ?$ _% F7 X' _# R" T4 R
<p>安装完毕后让我一起感受一下stern的魅力吧,我的Pod里面有两个容器:webapp和busybox,如果使用kubectl logs 还得指定具体的容器,而使用stern就没有这样的限制。</p>
0 U0 Y% y5 H" ?2 T8 {<div class="cnblogs_code">$ }, }3 Y5 j! u, _
<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)"> .+ N# d# O8 P0 }6 \, P
</span>+<span style="color: rgba(0, 0, 0, 1)"> webapp › busybox$ L- q$ l. w5 `% \
</span>+<span style="color: rgba(0, 0, 0, 1)"> webapp › webapp
# A$ t" v6 Z  uwebapp 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)">]% D, J, Y+ `- @( 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)">53.200</span><span style="color: rgba(0, 0, 0, 1)"> [INFO ] [main] [org.apache.catalina.core.StandardService] Starting service [Tomcat]
( O$ U& g* J: L3 ]6 g. H- Zwebapp 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)">]
- |( {' P& W9 y. `- T# owebapp 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
5 f7 @, z) s/ W9 Mwebapp 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
9 Z2 z# @9 _4 Y' t0 \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.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)">+ n" t; B, B% P
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)
0 j; e& `- ]' B% A- p7 M* _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)">]% K- \% [- Z; V# h6 P# K! F! N
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.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)">
; ^6 Z6 [7 O& n. 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)">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)">)
, a7 F! C# s1 M+ K0 uwebapp webapp! n% A- B% Q/ R3 g1 _
webapp webapp   .   ____          _            __ _ _; d' i5 {7 v0 j! L) E# j
webapp webapp  </span>/\\ / ___<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">_ __ _ _(_)_ __  __ _ \ \ \ \</span>6 R0 ^) @% G! K; ]
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>
: [% Q# P. z" Xwebapp webapp  \\/  ___)| |_)| | | | | || (_| |<span style="color: rgba(0, 0, 0, 1)">  ) ) ) ): A% ?: i: F6 I- g
webapp webapp   </span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">  |____| .__|_| |_|_| |_\__, | / / / /</span>
4 i. Y9 \5 k0 m, g, m: |( zwebapp webapp  =========|_|==============|___/=/_/_/_/<span style="color: rgba(0, 0, 0, 1)">
" n% }: e5 k) R) @# S" Kwebapp webapp  :: Spring Boot ::                (v2.</span><span style="color: rgba(128, 0, 128, 1)">4.2</span><span style="color: rgba(0, 0, 0, 1)">)
- X& o8 k9 O1 z5 wwebapp webapp
* }( I& w5 x; H: Owebapp 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)2 e5 [8 V6 x$ `# @" P( U) l
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: default8 T  M! h3 E. N) 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)">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)6 D% h0 g+ e; v- d
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)">]
6 h6 v: j! w1 b0 o- nwebapp 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]4 M: [* }0 f# {/ E" T; 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.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)">]) D4 B! L% X# h- t" t5 K# p
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) |4 [4 z# g, i3 y, 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.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)"> ms8 W* w) ^) u' f' e8 o0 ?) P
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)">) L/ _% e, A% m" _1 g
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); H- I# i* H2 m4 q3 O" F
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)">]; q6 u! U, e7 ~5 P& `" `$ 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)">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)">! `! Y# G6 i) Y- A: c# F
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>
( w# E' }4 N, `* M- v- j</div>- g( `: C5 X. M6 g9 u
<p>&nbsp;</p>
# `: T2 W0 ?6 o& I. Q/ p, ^2 T
回复

使用道具 举报

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

本版积分规则

手机版|飞雪团队

GMT+8, 2025-7-3 17:54 , Processed in 0.074366 second(s), 21 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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