飞雪团队

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

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

[复制链接]

5344

主题

5432

帖子

1万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
18354
发表于 2022-2-12 14:35:42 | 显示全部楼层 |阅读模式
# h- w9 E+ b% }; y# ~0 \
<p>kubectl作为我们主要的操作K8S的工具,其具备非常丰富的功能,但是如果不经过打磨,使用起来还是存在诸多不便,今天我们来看看如何将我们的kubectl打磨的更加易用。</p>% [' K# f1 s& {2 y8 y. y4 R
<p>&nbsp;</p>+ [$ c: f4 g: d: I: x& h/ ?( b
<p>一、命令自动补全</p>
$ N  r7 i) g5 @* V" V1 v<p>kubectl中提供非常多的命令,如果每一次都要手动一个字符一个字符的敲未免太累了,那么如何配置自动补全呢?这里以ubuntu系统为例:</p>4 I$ `3 L' R" Q1 a& I
<p>1、安装auto-completion工具</p>
; p8 `" K9 c( ]7 w7 L" D<div class="cnblogs_code">$ ~% z* t5 l( d. H
<pre>$ <span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> apt update
$ B9 h5 f5 c! n7 _1 l" XHit:</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>
# R) W( ~9 f3 r+ j# CHit:<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>
7 ^* K5 [( B- O# \4 u" PHit:<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>* e# g/ R# I1 M7 g$ p
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>  @. ?. G2 j# D5 B% d& u5 N# L
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>9 j# y! l3 }- C/ R* i5 Z
<span style="color: rgba(0, 0, 0, 1)">Reading package lists... Done
- v" [% L' q0 [' f$ {1 t$ u! eBuilding dependency tree
! u8 z& ?! s1 S! C1 AReading state information... Done. W* u. V4 M% C: B/ T3 C
</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.8 [: s) J; B$ {! G% B
$ </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
9 z; O$ G( z* F, X9 FReading package lists... Done& [7 w/ J2 K) M8 h% |' C$ j
Building dependency tree
( Y# ?3 c4 H7 ?; w" XReading state information... Done, E! @: T8 P6 d& k, m7 R! x5 x* a
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).( O. P- N) l+ @0 t' L9 t
</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>3 g4 Q( k& [8 G4 s: |
</div>
) b- c! f. m+ R- R- _3 ^<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>
  s% Z9 n& g4 `- ]) c. e* {<p>2、<span class="js_darkmode__1" data-darkmode-color-16446330660319="rgb(163, 163, 163)" data-darkmode-original-color-16446330660319="#fff|rgb(0, 0, 0)" data-style="color: rgb(0, 0, 0);">配置自动补全<br></span></p>6 F" x% {6 x8 }" m) N
<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>' }' E7 |; P: L. k1 `7 S
<div class="cnblogs_code">) [2 R: G0 N0 p. {- P
<pre>source &lt;<span style="color: rgba(0, 0, 0, 1)">(kubectl completion bash)
( b3 T8 t/ u6 x  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)">source &lt;(kubectl completion bash)</span><span style="color: rgba(128, 0, 0, 1)">"</span> &gt;&gt; ~/.bashrc</pre>
; f2 ~, W) Q! C' l5 n$ S( z</div>
; Z- {+ c" s6 k' ]" s; p7 h9 C<p><strong>Zsh</strong>:</p>- {, K* r# |$ E% T9 L, }# }0 i
<div class="cnblogs_code">+ Q+ S0 P% T7 L6 U# z
<pre>source &lt;<span style="color: rgba(0, 0, 0, 1)">(kubectl completion zsh)
6 e4 d& I. c) U5 m</span><span style="color: rgba(0, 0, 255, 1)">echo</span> <span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">[[ $commands[kubectl] ]] &amp;&amp; source &lt;(kubectl completion zsh)</span><span style="color: rgba(128, 0, 0, 1)">"</span> &gt;&gt; ~/.zshrc</pre>
3 o& g1 H. P5 C' i! |( d</div>
$ ^! I. u/ Q" I! Q% |3 [; E<p>配置后就可以通过Tab键自动补全命令啦!</p>. t, L6 j& l- t& ~9 `
<p>&nbsp;</p>9 d7 F1 ^& p, P# h8 \
<p>二、配置kubectl别名</p>. y2 R# r9 j4 P: Y7 A6 i
<p>我们可以通过设置别名简化kubectl命令,编辑.bashrc文件,添加如下内容:</p>
7 X0 A; ?' v2 u8 Z% |<div class="cnblogs_code">
6 J0 a8 h- R$ E' J<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; w0 d( R" k
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)">. ]; @$ S0 I1 A8 e8 g. A5 t4 B
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 z' o) ~- e$ C% J4 P- C
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)">
7 P. N6 ]0 I* U* E6 M6 ialias 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)">5 A1 @9 A* C1 \! {. F4 q, o
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)">
# T6 c# c2 E2 p- p2 ]& C8 \: calias 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>0 @: B; n6 f4 U7 h3 H% p
</div>" o. F, c: |& z! L$ M1 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>) R  t$ X4 a' D# J. T. ]& X: K4 R
<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>, n: r3 b% d4 m7 l, z" G* p
<div class="cnblogs_code">
. d# R5 z1 j* a  R, J8 b<pre>$ <span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> ka webapp_pod.yaml
1 h2 Z8 P" `1 p5 n1 l3 Jpod</span>/<span style="color: rgba(0, 0, 0, 1)">webapp created
3 ]$ o7 n1 Q  d- v, m$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> kg pods6 ^; X: v) Q+ R4 j+ n" w
NAME     READY   STATUS              RESTARTS   AGE& ]9 C3 I$ \' C( g9 c; v
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& k+ w) j% E4 O4 L
$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> kd pod webapp3 ]) W9 E; X5 B& x& q  f& R
Name:         webapp6 V; j& }6 \. g+ R5 I: ~
Namespace:    default
% S( z& [* B5 R# I3 lPriority:     </span><span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">  b# H) K0 h- O
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)">
8 q+ N* c8 K( l  _- F; ~. PStart 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)">8 b2 x- @7 P; b$ v" O; M- w3 q
Labels:       app</span>=<span style="color: rgba(0, 0, 0, 1)">webapp
/ q! `6 P) ?$ Q" ]7 }% o4 {Annotations:  </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">+ H+ c" r* p4 x0 k+ q0 q
Status:       Running3 O  ^# o4 a/ \, y' C0 X  `* a9 u$ S
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)">
/ U/ M) D' W5 m5 g" lIPs:
+ S+ v6 V( N4 L) T" e  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)"># C5 h3 o6 H6 D" O# j2 l/ ?
Containers:
+ r- `0 m4 n* e6 n( C5 J  webapp:; _6 Q! Q* C. U
    Container ID:   docker:</span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">d9ddf9dd47de12b53f2119bf75df6706bee2e7711509638ad52adc9addeda704</span>' u3 G) S. b# @% t$ b' A
    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)">0 D% V9 B; D6 h1 j5 c
    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>9 }9 ^5 {0 g, Q
    Port:           <span style="color: rgba(128, 0, 128, 1)">5000</span>/<span style="color: rgba(0, 0, 0, 1)">TCP
' Z8 N% q4 x* U# q, {: _! ?3 i    Host Port:      </span><span style="color: rgba(128, 0, 128, 1)">0</span>/<span style="color: rgba(0, 0, 0, 1)">TCP; v$ L$ O7 n# V0 ~) g8 I+ D/ p2 I" ~. q
    State:          Running3 q4 w6 O8 s! K* ~# ~
      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)">! G* ]9 B) {( c3 w1 M8 F  Z
    Ready:          True( d7 g# O: L, @* F: v
    Restart Count:  </span><span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">
/ P: c# d3 }) H    Environment:    </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">
# Z" c; _- i9 U2 Q    Mounts:7 t5 a) V! G+ q9 J$ c$ Y
      </span>/tmp from webapp-<span style="color: rgba(0, 0, 0, 1)">logs (rw)5 Y( Q# n6 A) M
      </span>/var/run/secrets/kubernetes.io/serviceaccount from default-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h (ro)
3 r: M. D) l3 c0 m( P9 e  busybox:1 d0 H& b0 t8 A; N7 |* E, o
    Container ID:  docker:</span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">6a6a35a628a782fc643af3dd49986bbc77c23de1ae4726bc521c77f61abbbf5d</span>
2 x5 Z$ ?! U( ]% g# j* ~% a- R% ?<span style="color: rgba(0, 0, 0, 1)">    Image:         busybox
& M+ f1 y, V$ f& M6 s    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>
; G5 q% ]* m0 K3 Q- d    Port:          &lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">
$ |$ U. t. p2 i2 F" q$ E6 r    Host Port:     </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">
  k% t" k" c6 ]) r# O    Command:- U) T+ L5 F' n9 B( ]. b
      </span><span style="color: rgba(0, 0, 255, 1)">sh</span>1 f" o# w5 `2 J# d* j
      -<span style="color: rgba(0, 0, 0, 1)">c' y  K( T! A/ f0 j
      </span><span style="color: rgba(0, 0, 255, 1)">tail</span> -f /logs/<span style="color: rgba(0, 0, 0, 1)">log.out" N- P: C# |; ]+ Y
    State:          Running
4 C$ G" Y! b+ S7 T. n9 q1 k      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)">) b, ], t6 @+ C$ V( g
    Ready:          True
; j2 T& Q4 k/ K    Restart Count:  </span><span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">( I4 p' W& z4 Y; S: G4 T
    Environment:    </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">
0 H5 Q6 k  B# }% y    Mounts:
5 e8 j. }3 A( n8 D7 I$ A, w( C; q      </span>/logs from webapp-<span style="color: rgba(0, 0, 0, 1)">logs (rw)
0 \9 H8 ^& c+ b      </span>/var/run/secrets/kubernetes.io/serviceaccount from default-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h (ro); o6 K( `! O' ]+ e- M, l
Conditions:
7 q& A+ j3 S7 A/ F, F5 \) `/ ^  Type              Status
+ P" [) r% E& y5 k% E, _  Initialized       True% U3 g+ m0 }8 \  o/ I7 p
  Ready             True
) [/ w" E, P) x0 C1 N% ~& }  ContainersReady   True
" t$ f$ x& ^- ~% F- L6 h  PodScheduled      True
$ F7 K6 w( x% |' RVolumes:, J3 a; a7 D( y+ r, Q, P
  webapp</span>-<span style="color: rgba(0, 0, 0, 1)">logs:
; Z! {2 i& ?' D" n* y% I" _    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>; t. P# d+ Y" ~8 K; M/ F
<span style="color: rgba(0, 0, 0, 1)">    Medium:/ {$ Z" i+ m3 x
    SizeLimit:  </span>&lt;unset&gt;<span style="color: rgba(0, 0, 0, 1)">
+ k' y0 c2 I3 \" g7 L4 M8 S  default</span>-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h:
/ S) @- m0 u8 {# K  W! p% A' U    Type:        Secret (a volume populated by a Secret)
# h; @' G& D/ p& w8 E: H7 R/ s    SecretName:  default</span>-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h
/ R: V: P+ f7 J. A$ u    Optional:    </span><span style="color: rgba(0, 0, 255, 1)">false</span><span style="color: rgba(0, 0, 0, 1)">
; b3 b8 t* |# P. WQoS Class:       BestEffort
& d% v! m7 S" p, ZNode</span>-Selectors:  &lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">
7 A) r* W9 n: \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% v: J: r4 J4 S- K# L, N' n
                 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
7 }2 q$ u+ g& T1 `% OEvents:
# j6 ?, @; i3 ~  Type    Reason     Age    From               Message! ?5 W* w0 j) u, d. f- O5 v/ |
  </span>----    ------     ----   ----               -------<span style="color: rgba(0, 0, 0, 1)">2 C- |1 T! M* |+ m0 q
  Normal  Scheduled  2m23s  default</span>-scheduler  Successfully assigned default/<span style="color: rgba(0, 0, 0, 1)">webapp to ayato  d! g) m3 Y- I* Y( O: I) w' p5 t
  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
- c# `6 n" l- S) H4 Y: C  Normal  Created    2m21s  kubelet            Created container webapp
" m5 o" ~5 h1 n  Normal  Started    2m21s  kubelet            Started container webapp- v" `$ k/ w8 C2 I, J6 w( H! K/ E
  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)">
) g+ q  S+ z9 P1 i  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, a: h. L6 ?1 B5 R# S) C5 K/ r% V
  Normal  Created    15s    kubelet            Created container busybox
4 O& p) I# b- B% e' J$ J! j  Normal  Started    14s    kubelet            Started container busybox</span></pre>4 g, e* ^/ j! U; S" f: @0 L
</div>
, g* _$ o- ?& {5 O<p>真的是飞一般的感觉!!!</p>
6 M% z+ N8 P; w2 j5 }# r<p>&nbsp;</p>3 {) B4 m" v- I2 \# G) x
<p>三、Context和Namespace切换</p>6 f! \  `0 g- v0 C  q
<p>我们在公司的容器平台上使用kubectl时,经常需要切换context和namespace,导致命令非常繁琐,那有没有简便的方式呢?—— kubectx</p>
& M' k" E7 D1 k<p>kubectx安装</p>0 k  ^% X( v: A$ A
<div class="cnblogs_code">
( q/ j/ d; Q! Z" v<pre>$ <span style="color: rgba(0, 0, 255, 1)">sudo</span> git clone https:<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">github.com/ahmetb/kubectx /opt/kubectx</span>
4 J8 p  x* {( K4 G6 FCloning 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)">...  `- b1 J* C- q- G  W
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)">.  N1 t8 j* e. O# ~3 N" E6 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)">.4 g+ X1 \% A' {. U( \. o
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)">.
5 i' p5 F' n  B# @; k6 o4 hremote: 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)">: f% y* y9 i2 P
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)">.8 `$ A! T3 L5 j% o( @5 f  R
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)">.
6 d/ [) o/ O* b0 H( x$ </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) \) d2 C" r1 x8 E0 T. y4 q6 h
$ </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>: G2 g/ I2 M+ f, B8 u& y
</div>8 J. d5 C& V" l( C
<p>我们来看一下效果:</p>
" `  b% I+ U. g+ H$ f6 [<div class="cnblogs_code">
9 p% g1 P$ X( b& H7 |<pre>$ <span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ctx. y  U/ x3 m1 N% t: t
minikube! Z8 u5 w# Q; ?/ h( S7 X8 r
$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ctx minikube5 r' h1 _+ B) s8 E1 c" s$ r
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)">.: K' g4 p9 k- h) G3 n: g; z) O; w
$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ns+ }0 F7 l8 j$ ]/ s/ h+ B1 n
default+ w& A4 u) t  n8 r
kube</span>-node-<span style="color: rgba(0, 0, 0, 1)">lease
4 R" v8 x9 u3 g+ Jkube</span>-<span style="color: rgba(0, 0, 0, 1)">public
: a$ T( Z7 |' x( I3 i, l; bkube</span>-<span style="color: rgba(0, 0, 0, 1)">system: K7 S5 t4 x7 }
kubernetes</span>-<span style="color: rgba(0, 0, 0, 1)">dashboard% n0 i# {. @* A& H4 m- l9 H
$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span> k ns kube-<span style="color: rgba(0, 0, 0, 1)">public
( R/ C3 c, }& }) a* W( B) d7 j& E( RContext </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.
% k2 [7 ~5 }5 F1 w2 g5 z& qActive 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)">.1 Z1 e/ k4 D5 |$ [( H& I0 B
$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ns default, N2 p; b$ W1 @0 E
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.
* q. Q0 K( H2 u( O) U. [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>2 r4 j' {1 }) r& e  k* s
</div>0 s  y5 o$ q7 `: R6 p
<p>&nbsp;</p>
2 A/ h  o6 M' o0 U4 M0 S$ ~<p>四、跟踪查看多个Pod的日志</p># i0 l3 L, N( S9 C0 y/ g9 N- m1 E
<p>我们一般使用kubectl logs命令查看Pod日志,但是它不能通过-f参数同时跟踪查看多个Pod日志,这就不方便了,毕竟实际生产环境中每个服务都会有多个Pod,这时我们可以使用stern这个工具,它具备如下能力:</p>' \4 H5 X+ d& l7 [' p1 b$ q$ k$ ^
<ul class="list-paddingleft-2">
1 S: K  H% h( ~, a& ?<li>
- Y7 `# S; P+ s6 U- E6 n9 d<p>允许使用正则表达式来选择需要查看的PodName</p># T8 A+ |5 L" z9 \+ V
</li>
% b! ~- u; F6 r3 R3 \<li>
" v# F+ p( e; N+ I% J9 M<p>为不同 Pod 的日志展示不同的颜色</p>- h9 {, J. Z4 v" ~
</li>  o. s+ ~- t/ b, u/ g
<li>( K5 }# V. K9 e3 V# W: v2 G
<p>跟踪日志过程中假如有符合规则的新 Pod 被创建, 那么会自动添加到输出中</p>
3 d! ]2 y) z' q</li>" {8 g' |) }$ T, s; i
</ul>
5 X! X; Q4 [- c( E# S2 a7 f<p>首先安装stern(下载stern时可能较慢可以多试几次):</p>
( b9 E" l, {7 A# ?" H<div class="cnblogs_code">3 k8 i% p, l: H' |) K
<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>, u2 z" e& g; E
<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>
" @% B! q! |% i, m<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>8 S' k4 o) B2 @' H8 K. x# [& f
</div>
( r0 f& I0 q' [4 s2 _. z<p>安装完毕后让我一起感受一下stern的魅力吧,我的Pod里面有两个容器:webapp和busybox,如果使用kubectl logs 还得指定具体的容器,而使用stern就没有这样的限制。</p>" N5 `1 b. _3 O! R
<div class="cnblogs_code">" M" w( v# G9 L* d+ Y
<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)"> .( W( F# X8 r" P% r5 [# x
</span>+<span style="color: rgba(0, 0, 0, 1)"> webapp › busybox
$ m( v: m* o/ K</span>+<span style="color: rgba(0, 0, 0, 1)"> webapp › webapp& X! H) U* n/ K- F' g0 b6 @9 [
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.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)">]
* g' s% J& G% x( u* cwebapp 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]
" P; w( R; O) p8 ^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.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)">]
6 C" y. J6 u# n; U: G9 G- jwebapp 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
1 T+ b+ @  o& o; `/ v9 A" h6 F$ 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.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; q3 Y0 l  ^  k# o7 V& E. i; m3 O
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)">
9 ?0 z' T( o& h- [8 U) v( Awebapp 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)1 F+ q7 V3 b" m2 ^; `, k
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)">]. L9 E3 C/ z$ b6 F  q, b5 L- 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.481</span> [INFO ] [main] [org.springframework.boot.web.embedded.tomcat.TomcatWebServer] Tomcat started on port(s): <span style="color: rgba(128, 0, 128, 1)">4567</span> (http) with context path <span style="color: rgba(128, 0, 0, 1)">''</span><span style="color: rgba(0, 0, 0, 1)">5 j! W" x. A; @) t; h
webapp busybox </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">54.509</span> [INFO ] [main] [org.demo.webapp.todolist.TodoListApplication] Started TodoListApplication <span style="color: rgba(0, 0, 255, 1)">in</span> <span style="color: rgba(128, 0, 128, 1)">6.235</span> seconds (JVM running <span style="color: rgba(0, 0, 255, 1)">for</span> <span style="color: rgba(128, 0, 128, 1)">8.074</span><span style="color: rgba(0, 0, 0, 1)">). ~5 A1 m/ `" p
webapp webapp
( \/ W5 v+ t6 W+ P5 jwebapp webapp   .   ____          _            __ _ _& [0 g+ [+ y: G
webapp webapp  </span>/\\ / ___<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">_ __ _ _(_)_ __  __ _ \ \ \ \</span>
/ Z1 r/ z: m1 Q! ^: c1 I1 fwebapp 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>
1 }' o: p9 F1 twebapp webapp  \\/  ___)| |_)| | | | | || (_| |<span style="color: rgba(0, 0, 0, 1)">  ) ) ) )
9 v0 t$ F. y6 E3 b' Iwebapp webapp   </span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">  |____| .__|_| |_|_| |_\__, | / / / /</span>
6 M! Q6 {2 }2 D* E5 \+ Pwebapp webapp  =========|_|==============|___/=/_/_/_/<span style="color: rgba(0, 0, 0, 1)">
& [+ w/ v6 T* ^# i) {webapp webapp  :: Spring Boot ::                (v2.</span><span style="color: rgba(128, 0, 128, 1)">4.2</span><span style="color: rgba(0, 0, 0, 1)">)3 L  _$ e0 c' h+ e
webapp webapp
3 z+ w* d: ^8 I& |" Awebapp 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), j& A3 X' @5 p; \. q1 `' J- 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)">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% a7 @/ E$ S" L# w! W8 x
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)1 {; e2 c5 s: v0 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)">]
$ o7 k# f1 f7 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.200</span><span style="color: rgba(0, 0, 0, 1)"> [INFO ] [main] [org.apache.catalina.core.StandardService] Starting service [Tomcat]
6 ]3 w9 _- A6 n( a* _. a/ 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)">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)">]: r7 U; p9 W: q" ?5 `: _* 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.324</span> [INFO ] [main] [org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/<span style="color: rgba(0, 0, 0, 1)">]] Initializing Spring embedded WebApplicationContext' ~! U2 j5 Y- T& i$ n8 c" 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.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
, M3 \/ o9 q& g* b3 f" N7 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)">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)">
  A( F6 i: I+ F2 H2 u! b+ kwebapp 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)
3 n  j* X7 a7 ?" _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)">]9 a+ ~' \- n! N4 o0 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)">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) h, o  X3 \
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>
* K. P5 _9 w- B! J</div>7 ]# o- ~0 v1 y; [9 N* R1 D1 f7 r
<p>&nbsp;</p>, U, i* u3 U0 q- W& E" y2 ^6 {4 g
回复

使用道具 举报

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

本版积分规则

手机版|飞雪团队

GMT+8, 2024-11-24 03:08 , Processed in 0.072214 second(s), 21 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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