飞雪团队

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

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

[复制链接]

8058

主题

8146

帖子

2万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
26504
发表于 2022-2-12 14:35:42 | 显示全部楼层 |阅读模式
6 F% ?. U! |5 t0 ^/ t# C% t% {
<p>kubectl作为我们主要的操作K8S的工具,其具备非常丰富的功能,但是如果不经过打磨,使用起来还是存在诸多不便,今天我们来看看如何将我们的kubectl打磨的更加易用。</p>
' x5 A- B  ~( [: e; m<p>&nbsp;</p>6 ]$ r- E! K& b& l* K- h2 n% G
<p>一、命令自动补全</p>
. a% l& w; u# \9 ]5 C<p>kubectl中提供非常多的命令,如果每一次都要手动一个字符一个字符的敲未免太累了,那么如何配置自动补全呢?这里以ubuntu系统为例:</p>4 y& u" C7 E& @/ E5 y. t" e
<p>1、安装auto-completion工具</p>
2 R0 Z1 b8 H# ^% ~& Y9 y  f<div class="cnblogs_code">* G! r/ Z) g- b
<pre>$ <span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> apt update
0 o' }7 s7 v  Z1 x6 @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>, S( @" O  B" K5 e# |% s5 p
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>
* M+ c/ @1 H* e$ QHit:<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>
2 N8 E7 K. Q# V, lHit:<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 |' u7 m5 d. s
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>' N% J0 d* U; @5 V% _( v, U! c5 ~" Z" F
<span style="color: rgba(0, 0, 0, 1)">Reading package lists... Done2 c5 z( Q  Y# G3 {3 |# S
Building dependency tree
5 @5 m* t9 L; v8 ZReading state information... Done4 L& f" O0 o- S/ s
</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.2 E, K0 G0 w4 n3 c' `  T
$ </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
+ Z9 r0 L2 T( BReading package lists... Done
) R  Q6 q* f$ B  t. u7 r8 `: wBuilding dependency tree! `: `; ~# v; M2 z/ f
Reading state information... Done
% S0 l4 c8 K3 {2 c2 I" t. |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).( K, `+ n; 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>
6 E, J. `+ N. ?) p2 ?: W</div>
) U. d4 S: P6 h<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>
" ~- D4 S& A0 ?$ j<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>
0 Y; f5 I/ I" l+ }% v/ K. x( Y! {<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>
0 l" e# m+ |7 W5 L" u" {9 Z<div class="cnblogs_code">: {' g" B4 I1 R3 n# J. |9 v3 F
<pre>source &lt;<span style="color: rgba(0, 0, 0, 1)">(kubectl completion bash)( n# K& d! q5 U1 g
</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>  h! l- v. C, z% A$ I
</div>
6 _: H! u: P8 H: B9 c<p><strong>Zsh</strong>:</p>
( W" j1 @" M7 e' I2 K8 O3 H& E<div class="cnblogs_code">
3 n* i9 V5 r# |' k; |<pre>source &lt;<span style="color: rgba(0, 0, 0, 1)">(kubectl completion zsh)
" p/ `8 R4 O5 m) G5 `, H</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>% T" x, B; p# u  @
</div>
' k& ]% j# ?, k" |+ i$ u<p>配置后就可以通过Tab键自动补全命令啦!</p>' M+ h5 c1 `+ @/ O, N
<p>&nbsp;</p>
/ S/ D& q6 ?6 B" m<p>二、配置kubectl别名</p>" R1 F* V( P1 `6 k: Z
<p>我们可以通过设置别名简化kubectl命令,编辑.bashrc文件,添加如下内容:</p>3 a6 S( U) w) i8 F+ m
<div class="cnblogs_code">3 G; O6 f  G* Y' H3 m  b5 e$ ^  p
<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)">( [& k2 ]0 o* ^4 V) O
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)">/ T, f& {1 w! t1 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)">
9 L0 a# m2 X+ I( k6 Halias 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)">0 f" ~' u! G. a5 l, E
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)">- F7 S3 U9 R; R- V% s9 L
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)">, R1 H* Y/ i' w" {" d
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>
( z4 ^$ b  L2 Z8 ]9 K  \</div>
! x/ n! Y0 w# h) m( J% v5 q<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>+ h/ t/ Z4 x1 p
<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>
) M; s4 @/ T! Y9 S<div class="cnblogs_code">' L" E  U- p" c" e+ |
<pre>$ <span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> ka webapp_pod.yaml
' h! \6 M/ p' Z6 o5 ypod</span>/<span style="color: rgba(0, 0, 0, 1)">webapp created
( H8 X' j; D9 V6 _: X5 O. Q- k8 i# D$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> kg pods
9 `2 G3 V. |+ m) ?, e% G! S3 ZNAME     READY   STATUS              RESTARTS   AGE* m+ q) E2 Q7 A1 E" R' k8 T
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)">          7s
/ |* h. y: M$ c2 q5 P9 t$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> kd pod webapp: w  ^, \1 ^/ c9 i2 [+ a- D) x
Name:         webapp: {5 [7 L! e% Z1 l  L
Namespace:    default. @0 z5 _. P1 ~( A
Priority:     </span><span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">+ G9 [9 o5 d  W9 _3 u4 T0 `9 w
Node:         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)">4 s0 ^  a" r% D9 V
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)">, `6 {! M4 O+ [- v; V  A" h2 H
Labels:       app</span>=<span style="color: rgba(0, 0, 0, 1)">webapp6 t4 {. P* O( J5 p
Annotations:  </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">& o8 u$ R4 M% a4 |$ x& }! Z
Status:       Running8 u; ~7 e! M# E5 N( X& n
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)">3 n. `5 H& n* {8 b; @
IPs:
2 l8 [$ B& I; G2 \8 c  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)">
* Z$ _1 x. b/ DContainers:% L/ }. R, f' G7 X% @* w% O
  webapp:
; I  L: G0 N5 `    Container ID:   docker:</span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">d9ddf9dd47de12b53f2119bf75df6706bee2e7711509638ad52adc9addeda704</span>) R0 H+ c3 `; e( {  u* |6 q
    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)">
* R3 y! P  u6 g9 H4 t6 T% y9 G    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>6 g" H8 O8 m- [+ G. R
    Port:           <span style="color: rgba(128, 0, 128, 1)">5000</span>/<span style="color: rgba(0, 0, 0, 1)">TCP
8 M2 f# s8 o' H/ Y    Host Port:      </span><span style="color: rgba(128, 0, 128, 1)">0</span>/<span style="color: rgba(0, 0, 0, 1)">TCP6 l+ p' J0 N3 Z; b
    State:          Running
( v/ D$ N5 b0 K! N      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)">( e* _$ f* O& Q% z6 o5 |8 C
    Ready:          True- d; U1 _2 g3 c7 j" i  b3 ]
    Restart Count:  </span><span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">  l5 j: s- ?# a% }" J6 i
    Environment:    </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">* t5 Q( S+ \" Y
    Mounts:2 f/ J& [! t( O% ^# x2 R3 \6 _
      </span>/tmp from webapp-<span style="color: rgba(0, 0, 0, 1)">logs (rw)
3 a! |2 r( B8 H0 X0 q      </span>/var/run/secrets/kubernetes.io/serviceaccount from default-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h (ro)% z/ _' d+ p; y* d7 R# @
  busybox:
% d7 t# X+ O, Y( v7 G) O    Container ID:  docker:</span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">6a6a35a628a782fc643af3dd49986bbc77c23de1ae4726bc521c77f61abbbf5d</span>
: c) f; L6 b$ V' G) \<span style="color: rgba(0, 0, 0, 1)">    Image:         busybox2 e- X( R; r. D9 d: E
    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>" F& P. w. T/ A/ M0 n! C8 l7 w
    Port:          &lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">
& p8 L+ Y2 o% }    Host Port:     </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">8 D" R( ]8 o1 U9 m
    Command:
3 Q/ {  A) z* A$ U( R$ y: s4 h      </span><span style="color: rgba(0, 0, 255, 1)">sh</span>" c' }! i3 n9 m& C/ ?
      -<span style="color: rgba(0, 0, 0, 1)">c" T  ~5 k. p7 y0 h! N8 }. @
      </span><span style="color: rgba(0, 0, 255, 1)">tail</span> -f /logs/<span style="color: rgba(0, 0, 0, 1)">log.out
' V8 y5 Y( Q! t! w    State:          Running
0 [9 l# q# T- z, X% 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)">
2 S! w$ f/ b/ x) m    Ready:          True# H# u1 W- h; Y( P
    Restart Count:  </span><span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">0 J& t# ~0 C  W7 P6 [6 P
    Environment:    </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">- L; e, h2 j2 I) B; O" o3 N
    Mounts:
! ^& Q6 I6 E( K3 g; C! |: N. M      </span>/logs from webapp-<span style="color: rgba(0, 0, 0, 1)">logs (rw)
& M  s& u% C! c' z) h5 `+ v      </span>/var/run/secrets/kubernetes.io/serviceaccount from default-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h (ro)
0 S: T, t+ X# c* iConditions:. q& q0 x* Q; m% @" m9 ?! d1 ~
  Type              Status3 G+ ]+ J2 [: Y4 T7 |
  Initialized       True
3 C' U% ~" J8 J: E8 z! \1 }1 ~  Ready             True
( o; X) s+ v$ j& ^7 g$ P6 x' Z: R  ContainersReady   True
/ K5 H  d) f0 X: z8 P  PodScheduled      True% {. Z3 G9 |4 w# [1 @
Volumes:
5 x# n2 j" R5 s: c  webapp</span>-<span style="color: rgba(0, 0, 0, 1)">logs:  P- Z, w" A" ^6 m: t" R+ Q
    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>
- H/ ], L+ O) o' m6 Z( H& r<span style="color: rgba(0, 0, 0, 1)">    Medium:
$ m' E4 r+ I! h) @    SizeLimit:  </span>&lt;unset&gt;<span style="color: rgba(0, 0, 0, 1)">
0 o2 n$ a( g/ y' P  default</span>-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h:1 l) x* q; w; A
    Type:        Secret (a volume populated by a Secret)
( M9 x, O+ l+ z( ]! |- y, n    SecretName:  default</span>-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h
; _$ \# j$ s4 V8 D; L5 g4 M    Optional:    </span><span style="color: rgba(0, 0, 255, 1)">false</span><span style="color: rgba(0, 0, 0, 1)">( `+ `; }9 a  M+ ]" {# e
QoS Class:       BestEffort
. w- u* c' x& ~/ |# [Node</span>-Selectors:  &lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">' f1 e" c) A. Z! _0 E+ e
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
, I1 p. t6 E; c$ N9 |                 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)"> 300s6 Y0 l  D' }& F+ q0 j
Events:& B0 D" s+ j  f, w
  Type    Reason     Age    From               Message; d. ^# \; K- U6 Q' E- {
  </span>----    ------     ----   ----               -------<span style="color: rgba(0, 0, 0, 1)">5 d7 g; r$ Y% F$ S1 h1 z6 n
  Normal  Scheduled  2m23s  default</span>-scheduler  Successfully assigned default/<span style="color: rgba(0, 0, 0, 1)">webapp to ayato
3 I0 |4 L3 q6 \  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: c4 u4 o, F1 i- \! p5 Y
  Normal  Created    2m21s  kubelet            Created container webapp9 J! d) z+ c0 F4 E2 p3 H) Q
  Normal  Started    2m21s  kubelet            Started container webapp) w/ Y& a" B' w( N. Y( k
  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)">4 c3 G& a/ G6 L- j; a3 J9 a: g2 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)">.633078305s0 y* q5 v1 t' V9 H
  Normal  Created    15s    kubelet            Created container busybox" B! }1 i* c& [4 @) T0 u
  Normal  Started    14s    kubelet            Started container busybox</span></pre>
) d& z8 v6 e  ^0 Q6 D! K; S8 h& U* I</div>
& f) T( `2 m: T( ?0 V1 A" v<p>真的是飞一般的感觉!!!</p>. _) \5 d, }) k4 q
<p>&nbsp;</p># E* }  l. v8 ^# b/ t6 y4 v; x
<p>三、Context和Namespace切换</p>
3 N, C( f$ l' d' g<p>我们在公司的容器平台上使用kubectl时,经常需要切换context和namespace,导致命令非常繁琐,那有没有简便的方式呢?—— kubectx</p>
; [; o0 [2 W' d/ a  W<p>kubectx安装</p>$ ]# U7 C9 h( s# M6 X' p
<div class="cnblogs_code">: E& z0 J9 R' |  P, j% h
<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; N; B  u8 s) A# @
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)">...
6 D" x' F. _. O+ Hremote: 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)">.
  |! }2 X2 A* S) Z; }) R8 \% X; S4 Vremote: 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)">.
* w3 ]0 B8 i% k) iremote: 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)">.1 ~5 F3 E" Y4 Q/ Y( w
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)">' }3 K: ^* z2 D
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)">.! w  o& B, N+ P  }' i
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)">.
8 {, d: R0 S7 L6 ?. w. A$ </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)">ns8 L. _' k6 W; s4 F* M: 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>8 @5 p" G2 G/ l+ Q/ V* ]3 \
</div>7 ?3 i, ~: W1 l0 ~1 Z, X# q& l) P5 E
<p>我们来看一下效果:</p>
. o! h) s) X) k/ b$ }$ M5 k3 W<div class="cnblogs_code">" x+ i* i* M) D( H5 `* y1 g. ~' t' H) I
<pre>$ <span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ctx
3 t) `0 B1 k: V# d/ ?, G  bminikube/ G+ T- e: {$ n3 t
$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ctx minikube
1 ~1 q1 {2 ]3 b1 z1 |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)">." u" x, n% [8 u
$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ns
; j' a# G( X3 \2 p$ @default( \# k+ ?2 U: k) n( M% |9 f, m% P
kube</span>-node-<span style="color: rgba(0, 0, 0, 1)">lease
( m  z) Y7 r( @" M& G, _kube</span>-<span style="color: rgba(0, 0, 0, 1)">public- {; B- _5 O) W- |5 e3 F6 F
kube</span>-<span style="color: rgba(0, 0, 0, 1)">system
: I* [5 b" L; rkubernetes</span>-<span style="color: rgba(0, 0, 0, 1)">dashboard, ?8 y. f( P, \+ _6 F3 `
$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span> k ns kube-<span style="color: rgba(0, 0, 0, 1)">public' P% z8 D5 s: y9 b9 i$ p; s
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.  l- }0 [3 h' N( ?+ i' R9 g
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)">.
$ a2 c6 ?7 }: g0 E+ }+ k0 Y$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ns default
/ D# Z7 p( R" t3 ?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.
- n. Q2 ^: [9 ^/ i3 G& qActive 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>
" h1 Z6 o& |1 f; I/ W</div>, D" P/ c/ w( p2 q% v
<p>&nbsp;</p>2 H, _+ v- u5 |) w
<p>四、跟踪查看多个Pod的日志</p>
0 R7 Q. _) P' d9 h. r9 I- r- K<p>我们一般使用kubectl logs命令查看Pod日志,但是它不能通过-f参数同时跟踪查看多个Pod日志,这就不方便了,毕竟实际生产环境中每个服务都会有多个Pod,这时我们可以使用stern这个工具,它具备如下能力:</p>
( P3 }. @  n' S& w+ H<ul class="list-paddingleft-2">
9 q2 ~. m9 u; H<li>  H# t$ u' t9 ^
<p>允许使用正则表达式来选择需要查看的PodName</p>6 @% g2 G; e, y& g! _  C
</li>
1 e7 K# ?$ a# H6 E  `+ w<li>% f# c* `  m- v3 B
<p>为不同 Pod 的日志展示不同的颜色</p>& }) U& @: \- b# O. Q
</li>
, x; w7 M- x7 U<li>: r' m4 r2 k* T, x, U
<p>跟踪日志过程中假如有符合规则的新 Pod 被创建, 那么会自动添加到输出中</p>* F: n1 U/ x# c  h
</li>
. b" q5 r: c' H6 [9 J</ul>& i& a0 C2 t" |3 G
<p>首先安装stern(下载stern时可能较慢可以多试几次):</p>
3 n5 Y: k: F3 w7 ?9 X/ \  M' V5 g<div class="cnblogs_code">
4 K% U2 l2 x- t  n<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>* s0 [# M  ?" s) @9 j
<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>
8 F* H8 h+ B$ ]: [2 |8 _! v5 ?; b- 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>
. r5 z: I1 ?3 V2 Q& c7 N</div>
) r- {1 L* @* z6 N; P8 E% P<p>安装完毕后让我一起感受一下stern的魅力吧,我的Pod里面有两个容器:webapp和busybox,如果使用kubectl logs 还得指定具体的容器,而使用stern就没有这样的限制。</p>, ~  c1 ], r! l0 S
<div class="cnblogs_code">
7 g* U% L7 y3 x8 B& K<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)"> .
, T7 F' a, O8 ^6 F2 s</span>+<span style="color: rgba(0, 0, 0, 1)"> webapp › busybox
% b0 o3 b' D& g( N7 C, O</span>+<span style="color: rgba(0, 0, 0, 1)"> webapp › webapp
+ K4 V" v& x8 U2 z6 G- R' 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.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)">]  ^& n6 U0 M3 i% f$ l  C5 l% R6 Q7 ^) 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)">53.200</span><span style="color: rgba(0, 0, 0, 1)"> [INFO ] [main] [org.apache.catalina.core.StandardService] Starting service [Tomcat]
3 ?% X, |3 x) w+ u8 C: u' Bwebapp 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)">]
& k8 y' W( u2 t$ 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# N/ m9 s* y4 q" K" `) ~: z
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.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
" F3 O. Y# Y9 U/ A" 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)">/ ~) z  k3 I+ [8 H3 Q& G
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)5 B' Q( `9 {9 ]! b5 C* Y
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)">]
6 q% ?: S" F: x  M4 V6 Xwebapp 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)">
9 Z$ r/ U' h# xwebapp 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)">)
  f4 c6 {1 g" t0 W7 E4 iwebapp webapp: t% B' U) b1 V1 @2 |
webapp webapp   .   ____          _            __ _ _+ g1 l1 O) i! J8 B6 Z
webapp webapp  </span>/\\ / ___<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">_ __ _ _(_)_ __  __ _ \ \ \ \</span>
/ O' V: `, j3 w% J1 E: cwebapp 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>
( S# h/ A+ q* A# J& A" m" Kwebapp webapp  \\/  ___)| |_)| | | | | || (_| |<span style="color: rgba(0, 0, 0, 1)">  ) ) ) )% F; n5 E6 w2 p/ I/ f- K
webapp webapp   </span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">  |____| .__|_| |_|_| |_\__, | / / / /</span>* V/ d% s. D6 ^' ]' @2 @
webapp webapp  =========|_|==============|___/=/_/_/_/<span style="color: rgba(0, 0, 0, 1)">
9 k' W/ V+ _& I( S3 Q6 U7 Swebapp webapp  :: Spring Boot ::                (v2.</span><span style="color: rgba(128, 0, 128, 1)">4.2</span><span style="color: rgba(0, 0, 0, 1)">)
8 S8 x0 G7 ~! m* Pwebapp webapp
4 e. ~; F; X, ]3 a3 E% a6 [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): u1 t9 F" `% X/ 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.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 W# n+ F: L# ewebapp 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)
1 R, S3 R, B6 }: b# C* lwebapp 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)">]
( g4 S" f/ \0 M. F6 zwebapp 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]
& Z# `; O% Q) \4 B6 ]% Mwebapp 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)">]
( r3 u' W) p  t& R' r3 A9 q1 U4 ]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 WebApplicationContext5 v$ t0 j& v9 y  e: k- 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.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
& A. y# F8 n; n+ H. w! |) ]; {! O0 Y/ 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)">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)">* y; P% P6 w% p+ r5 }( w
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)
% g3 D- f8 r$ n  R( S  swebapp 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)">]) O* j5 J1 h; v; 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)">$ b5 K/ J5 T" M0 N( a
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 W+ q5 U" V5 j
</div>
: U& @# @1 L9 H) V; ~; O<p>&nbsp;</p>$ j$ A4 K5 w) x& ^0 {# V* Z
回复

使用道具 举报

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

本版积分规则

手机版|飞雪团队

GMT+8, 2025-12-13 13:44 , Processed in 0.070566 second(s), 22 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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