飞雪团队

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

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

[复制链接]

6993

主题

7081

帖子

2万

积分

管理员

Rank: 9Rank: 9Rank: 9

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

( ]2 Q) Q4 q) K3 j<p>kubectl作为我们主要的操作K8S的工具,其具备非常丰富的功能,但是如果不经过打磨,使用起来还是存在诸多不便,今天我们来看看如何将我们的kubectl打磨的更加易用。</p>
8 u# D4 |) H- H, J7 v2 A<p>&nbsp;</p>8 m. q+ }8 [! L3 e8 w
<p>一、命令自动补全</p>
5 U$ ]' [( [4 f/ B# c3 a" C<p>kubectl中提供非常多的命令,如果每一次都要手动一个字符一个字符的敲未免太累了,那么如何配置自动补全呢?这里以ubuntu系统为例:</p>9 H! R2 @5 J' H
<p>1、安装auto-completion工具</p>
% a7 H4 B+ \' [4 \1 n<div class="cnblogs_code">4 v; B9 t! J7 ?  W$ ~4 y
<pre>$ <span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> apt update& e4 \6 \6 I4 K: x/ f# T0 N
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>* ]0 ^; o% R- a: Y. W
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>
5 s1 ?# S1 k; i. J) Y0 `- O# s( 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>- R: F/ V. L0 N) p% O- \( B! 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>
3 H0 Q% ]9 {2 r2 jHit:<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>/ X: `' z# _: L: E. f
<span style="color: rgba(0, 0, 0, 1)">Reading package lists... Done
  e! |( q4 a( J1 s! [( kBuilding dependency tree
/ w9 h( _( h5 @4 GReading state information... Done
1 t2 O3 E3 y& e/ I! U</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 I/ U$ U1 T( }$ i8 y$ </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
8 Y. Q$ p/ W5 k* s1 u5 _7 Z8 sReading package lists... Done
7 J# s5 P7 ~; c* [' g7 xBuilding dependency tree4 C5 c5 O: s: f6 c
Reading state information... Done
* O2 `+ C( @5 X; Z0 M7 Xbash</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).
% q! t7 j4 g7 W: c+ U* W</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>% x2 M9 o$ v% [8 Q$ ~# i3 N% h
</div>
) i$ `& k* B+ k) J! v<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>
) z" h9 p7 N0 N) X<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>
( Q4 o5 U, Y. H3 W<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>
9 k* U5 \' Z9 [2 T7 u<div class="cnblogs_code">
$ r  r3 y  ^) C$ B7 L2 G<pre>source &lt;<span style="color: rgba(0, 0, 0, 1)">(kubectl completion bash)5 V& H  O" g) r) a& j5 R
</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>3 [9 i; G* ~+ E  n( }
</div>9 q! F( l1 A# H- \
<p><strong>Zsh</strong>:</p>
/ P1 M; x& D- P% p<div class="cnblogs_code">
* x1 ^' Z& ^7 E2 h9 u% m<pre>source &lt;<span style="color: rgba(0, 0, 0, 1)">(kubectl completion zsh)
& @* D8 C* L5 ?5 j( t</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>
) g- T/ T0 ?& g</div>
- V6 p$ P8 v4 g7 f4 U' w7 v& n5 G<p>配置后就可以通过Tab键自动补全命令啦!</p>4 {. j# C/ C# G
<p>&nbsp;</p>
- \6 b' u. ]8 L  Q* B<p>二、配置kubectl别名</p>. m# m1 I- U! I9 y% {
<p>我们可以通过设置别名简化kubectl命令,编辑.bashrc文件,添加如下内容:</p>% I# t) R+ ^' }7 l
<div class="cnblogs_code">
) g. ~1 `+ Y( H2 L8 }<pre>alias <span style="color: rgba(0, 0, 255, 1)">sudo</span>=<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">sudo </span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">; J* F2 q! C" ~& l" r
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)">
* G" P! f" c+ F. o! t. N: Z! j( Yalias 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)">
& Q+ h2 y9 j( balias 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)">2 Y/ w! V( m+ O- E3 ~3 v; F2 Y1 A( W
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)">
. t$ G4 u  Q6 ?3 ~% D/ j! talias 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)">2 x: E+ f: i/ F& c/ o1 k8 e( L
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>
# n4 @7 g6 u$ Z</div>" K- d7 h4 p6 O! o/ |/ }
<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>2 y2 c! q9 p0 g9 n
<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>! s% m: N; R/ q
<div class="cnblogs_code">, h0 N" l9 t$ ^* ^/ w; _3 a
<pre>$ <span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> ka webapp_pod.yaml5 [! ~5 o" o3 H; ^/ B# K
pod</span>/<span style="color: rgba(0, 0, 0, 1)">webapp created1 R" a( W2 v( N) |
$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> kg pods
3 r; n2 J, o( q1 D8 [! R7 tNAME     READY   STATUS              RESTARTS   AGE  E. u& `, E+ `4 P9 O3 e! p
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
9 p* u- E% p) ]) i& i4 G$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> kd pod webapp+ v2 K% m2 ?* q6 d! [
Name:         webapp/ ~: N: i) U/ w$ ~
Namespace:    default( b+ z* d. r# T# J
Priority:     </span><span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">+ C4 O+ o+ Y/ b7 k. q; [
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)">, j) j8 C" b3 C6 T. o
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)">* [: m6 t9 z! x' v7 h2 B3 v" J
Labels:       app</span>=<span style="color: rgba(0, 0, 0, 1)">webapp& f5 X$ w8 k9 h; k4 ^' o* B7 Q
Annotations:  </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">
: V+ q/ X0 X$ a( nStatus:       Running
8 b' O0 `  }2 {: JIP:           </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)">
$ s: V: v# E5 p) {* m% Q9 XIPs:
8 f* Q7 m  B: w" K6 m+ x  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)">
! R2 }2 v9 h2 H; XContainers:
% p  O( _8 C8 g) m( l9 j1 {' R  webapp:, T/ s, K6 c, F1 l; Z! B; r. B
    Container ID:   docker:</span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">d9ddf9dd47de12b53f2119bf75df6706bee2e7711509638ad52adc9addeda704</span>3 V8 h) ^# {- J% c4 }; H0 i& 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)">* b0 T8 Z7 z  \! U- ]: c) R5 D
    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>
: c# K2 W  w# H  F    Port:           <span style="color: rgba(128, 0, 128, 1)">5000</span>/<span style="color: rgba(0, 0, 0, 1)">TCP
( b2 F0 M) x* D    Host Port:      </span><span style="color: rgba(128, 0, 128, 1)">0</span>/<span style="color: rgba(0, 0, 0, 1)">TCP
- Z1 q; ~6 C" r    State:          Running
1 A. S! L8 x5 [      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)">
5 }# ~, t' n; v8 o% m    Ready:          True) i# u7 @, R: D: n% E/ O
    Restart Count:  </span><span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">% E; U, e, K. Y5 [( @1 h. r! I0 @
    Environment:    </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">. t5 r; z2 `- Q" r; `0 N
    Mounts:
. {9 K# ]* Y8 u      </span>/tmp from webapp-<span style="color: rgba(0, 0, 0, 1)">logs (rw)6 P2 e$ Y  X  Q! Z
      </span>/var/run/secrets/kubernetes.io/serviceaccount from default-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h (ro)
! P% ^/ P) ~( V+ z# q5 t; G2 m  busybox:% m  q* r' x( c' G( j
    Container ID:  docker:</span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">6a6a35a628a782fc643af3dd49986bbc77c23de1ae4726bc521c77f61abbbf5d</span>* V1 k* g' j, g! x$ L( X/ n
<span style="color: rgba(0, 0, 0, 1)">    Image:         busybox/ ?2 e# r9 ~0 A/ ?
    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>' A- R5 `+ h8 |# B: J
    Port:          &lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">8 V5 _: H- y( E9 @: q0 G, M
    Host Port:     </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">
+ f# g; b( a0 N1 y" m    Command:
% u: l: j1 Q# J! \- T; z      </span><span style="color: rgba(0, 0, 255, 1)">sh</span>( ?5 [; B2 |( S0 H
      -<span style="color: rgba(0, 0, 0, 1)">c
! B% ?0 \) @% l" _$ ^) |      </span><span style="color: rgba(0, 0, 255, 1)">tail</span> -f /logs/<span style="color: rgba(0, 0, 0, 1)">log.out
' x, E( l9 N, I( x' C# o    State:          Running/ z5 y; n* e$ U* K0 C  X2 I
      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)">
) k" m; Q" s* V6 }& c6 _/ a    Ready:          True
5 V3 c. h# c% x( e    Restart Count:  </span><span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">4 f2 J& V+ Q; q  N0 l$ x! C
    Environment:    </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">
1 f* n' h/ m0 m$ W8 e4 b% c" X7 N. _    Mounts:
+ W* C8 Y: e$ D+ B3 L      </span>/logs from webapp-<span style="color: rgba(0, 0, 0, 1)">logs (rw)* ]' {$ e% T* U5 g
      </span>/var/run/secrets/kubernetes.io/serviceaccount from default-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h (ro)
( _" l$ f5 c' y6 w! ]" mConditions:4 |; r; l! y, q' U' S
  Type              Status
" \, a+ F7 f$ s  Initialized       True
! H6 S. j6 m2 k) D9 y- k* k  Ready             True
. f) f% W0 m8 J! g. P  ContainersReady   True
7 P& |. o5 E- F& h4 `# ^3 |& i  PodScheduled      True+ Y4 p8 P8 q, ?3 n' n3 `
Volumes:
' ?$ B4 O, W; g$ Z; W  webapp</span>-<span style="color: rgba(0, 0, 0, 1)">logs:
, w9 t5 S: B6 v. A, b0 |! u    Type:       EmptyDir (a temporary directory that shares a pod</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">s lifetime)</span>3 I" q+ s6 Y3 m1 l4 X. k) r( u
<span style="color: rgba(0, 0, 0, 1)">    Medium:, j* B5 L3 E9 z3 f6 W; W$ h
    SizeLimit:  </span>&lt;unset&gt;<span style="color: rgba(0, 0, 0, 1)">; A1 J& |! t2 {
  default</span>-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h:# k9 m* C" T2 V7 a
    Type:        Secret (a volume populated by a Secret)  T( Q) R" N' E. z
    SecretName:  default</span>-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h. v# h, X8 }0 X9 Z( N7 v0 V' `
    Optional:    </span><span style="color: rgba(0, 0, 255, 1)">false</span><span style="color: rgba(0, 0, 0, 1)">! U& N  Z4 y" z4 V
QoS Class:       BestEffort
2 u* A9 |3 _3 i2 ~; z$ w9 S# [) KNode</span>-Selectors:  &lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">
9 S+ w. s0 L' }& z# n6 {4 zTolerations:     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
. N1 J9 Q  c3 b                 node.kubernetes.io</span>/unreachable:NoExecute op=Exists <span style="color: rgba(0, 0, 255, 1)">for</span><span style="color: rgba(0, 0, 0, 1)"> 300s
0 J8 s% [8 H* {3 g! mEvents:+ O2 r% y+ }" w. I" F7 V3 f8 e
  Type    Reason     Age    From               Message
$ I9 t3 g* r4 _  </span>----    ------     ----   ----               -------<span style="color: rgba(0, 0, 0, 1)">
) G3 b6 E3 @4 y, Y6 Q  Normal  Scheduled  2m23s  default</span>-scheduler  Successfully assigned default/<span style="color: rgba(0, 0, 0, 1)">webapp to ayato( L5 b" M9 e# \  Z0 D- H6 D
  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$ T; x4 h0 J# b) j  B
  Normal  Created    2m21s  kubelet            Created container webapp. W" w0 N* `9 V2 L5 c' t! O
  Normal  Started    2m21s  kubelet            Started container webapp
( B5 x( N" p/ L$ j# @  Normal  Pulling    2m21s  kubelet            Pulling image </span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">busybox</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)">1 f9 p) O4 M7 B. a- r# _$ h3 [
  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
0 W% U4 J- i( g9 k; K3 B$ x  Normal  Created    15s    kubelet            Created container busybox
* C6 P; b4 v* K) p2 E0 P8 o  i' \  Normal  Started    14s    kubelet            Started container busybox</span></pre>, x0 {5 }# e; P8 A( P  a
</div>
* S8 l- |6 H) N/ x4 {0 r5 K<p>真的是飞一般的感觉!!!</p># [  m9 Z4 g" o$ p1 N
<p>&nbsp;</p>
& l+ i( y" x2 Y4 e<p>三、Context和Namespace切换</p>9 T+ s4 V1 C4 G8 @3 C/ h
<p>我们在公司的容器平台上使用kubectl时,经常需要切换context和namespace,导致命令非常繁琐,那有没有简便的方式呢?—— kubectx</p>
9 E$ w+ s1 R7 W, @- Z( M$ o' W3 C<p>kubectx安装</p>. m: F( {' [  h2 i
<div class="cnblogs_code">
4 ?4 h" Z/ m: c; b3 S6 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>7 s3 S% y0 S" |
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)">...
+ j! f7 c7 K' m' v+ C5 k6 u3 cremote: 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)">.' G; Y3 P" h( z  R
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)">.: i+ D% {& h7 K3 |4 q
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)">.
  j: `  K: z: g( p0 e' S& k1 q5 E, Xremote: 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)">
6 U/ U- L( z2 u- m2 W1 [- g" J7 _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 P2 G; I4 F* u5 Z) _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)">.
: E0 Y0 ?. D9 z. F. W+ J$ </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)">ns5 O  b2 g7 b4 _6 A0 w: w% G) N
$ </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>
  n8 ^& z  y, V$ e8 k- [</div>
! k8 d' I' r+ Z8 y<p>我们来看一下效果:</p>7 p1 k9 ]( B. L
<div class="cnblogs_code">
2 J( ]; t# C1 y5 w4 }/ J" r2 k; W3 J<pre>$ <span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ctx* r3 b( i4 o- m  r7 Q! H
minikube) S! l% |/ r. b9 d
$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ctx minikube$ j$ _3 m( v. U# }) Y! D  N
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)">.) k2 X* T# l% w2 ~
$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ns( ^9 l% x& w' n8 p
default
4 s8 ]* h! J* Q" X8 N! G/ F1 B5 bkube</span>-node-<span style="color: rgba(0, 0, 0, 1)">lease5 Z/ ~/ e4 s, H
kube</span>-<span style="color: rgba(0, 0, 0, 1)">public
  W8 N( p. R  c" }" l- l" ckube</span>-<span style="color: rgba(0, 0, 0, 1)">system0 O! N- f3 E  E' R
kubernetes</span>-<span style="color: rgba(0, 0, 0, 1)">dashboard8 P- G! {4 K' ]2 T& m
$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span> k ns kube-<span style="color: rgba(0, 0, 0, 1)">public
& D. A. u/ x' G& e: J! p* [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.
- {# m6 Q* G( rActive 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)">.
) R+ v; i  J# t' f; s2 a$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ns default. P( K3 b" f7 Z) @
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.
0 H3 d( W% B9 lActive 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>
# P1 H# v% q0 h! ]# P</div>0 N+ _% b( l9 ?4 U+ l( O
<p>&nbsp;</p>1 m! d, a8 z, l+ @, z( b2 G
<p>四、跟踪查看多个Pod的日志</p>4 A$ b! [/ p+ ]; D0 }9 y( Z- Z
<p>我们一般使用kubectl logs命令查看Pod日志,但是它不能通过-f参数同时跟踪查看多个Pod日志,这就不方便了,毕竟实际生产环境中每个服务都会有多个Pod,这时我们可以使用stern这个工具,它具备如下能力:</p>
9 S( j$ e: P3 Z( I+ n9 M( ]( I) |<ul class="list-paddingleft-2">
) ^5 n! W5 Y! g" ]# q& z! j# e<li>
) J% O9 w3 Y8 w5 O! X<p>允许使用正则表达式来选择需要查看的PodName</p>
3 R. D, ~, |& i$ w& K</li>" ^2 a# }( R. [& m/ d0 w5 z; i: m' a' w
<li>
: _3 f: g  o) z: e2 W+ y6 S<p>为不同 Pod 的日志展示不同的颜色</p>
. y5 I% e. i  D  r0 G</li>7 _" N$ ?2 \7 O1 Q1 Y
<li>
6 x4 k0 R7 h: Y1 q<p>跟踪日志过程中假如有符合规则的新 Pod 被创建, 那么会自动添加到输出中</p>  E6 h$ ]! `. g& U/ w  [8 O! ~! X* E
</li>
8 f1 K) ]4 N1 r) Y2 ]: w0 H5 u' |</ul>
  t2 B1 J, ^. T/ ]/ ]<p>首先安装stern(下载stern时可能较慢可以多试几次):</p>6 L8 }8 F# w) {3 t8 o, c
<div class="cnblogs_code">
; `/ i8 w9 Z0 X& Q<pre><span style="color: rgba(0, 0, 255, 1)">wget</span> https:<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">github.com/wercker/stern/releases/download/1.11.0/stern_linux_amd64</span>1 I& p( {7 r" S% I# D3 }5 p
<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>3 E) v' l" k4 X9 S2 |2 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>) P) M0 V1 m: f8 V
</div>
6 q" L+ j' s; }# R2 [' F<p>安装完毕后让我一起感受一下stern的魅力吧,我的Pod里面有两个容器:webapp和busybox,如果使用kubectl logs 还得指定具体的容器,而使用stern就没有这样的限制。</p>
/ ]$ s: V7 w$ O" K% _+ S) Q<div class="cnblogs_code">2 Q9 R2 G. L! b" F3 l- L4 e# M  E
<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)"> .
- a7 W# P5 D: }! o</span>+<span style="color: rgba(0, 0, 0, 1)"> webapp › busybox3 a8 [+ L0 h+ @! G/ S5 h
</span>+<span style="color: rgba(0, 0, 0, 1)"> webapp › webapp- L; [- m; R* Q/ P: 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)">53.197</span> [INFO ] [main] [org.apache.coyote.http11.Http11NioProtocol] Initializing ProtocolHandler [<span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">http-nio-4567</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)">]/ `9 Y/ M- f; a: C# b# |
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]% `( b. \  M5 e+ `; T! i
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)">]
- E- ~" [7 N3 W- B# Q+ T, hwebapp busybox </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">53.324</span> [INFO ] [main] [org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/<span style="color: rgba(0, 0, 0, 1)">]] Initializing Spring embedded WebApplicationContext
: E# @/ ]* V4 L" J) }3 vwebapp busybox </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">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 w1 g* T7 @1 V) c1 o* L0 \5 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.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* P* k6 a: S' V3 u" 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)">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)  E$ |0 P/ i# c) \
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)">]7 z( [/ e1 Y4 h/ U
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)">
& A+ S; y. `( }  H* 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)">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)">)
0 Z( o0 Y% w1 j5 @. L2 \webapp webapp
1 P" H. z2 l) Y# L+ i6 k. ]webapp webapp   .   ____          _            __ _ _
; _2 E" P* ]' w9 x' fwebapp webapp  </span>/\\ / ___<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">_ __ _ _(_)_ __  __ _ \ \ \ \</span>7 Z5 n2 n4 Y: X8 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>
- m' j1 k5 K6 A4 R; B7 uwebapp webapp  \\/  ___)| |_)| | | | | || (_| |<span style="color: rgba(0, 0, 0, 1)">  ) ) ) )
) t% A, k3 L, rwebapp webapp   </span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">  |____| .__|_| |_|_| |_\__, | / / / /</span>
, p0 ~; M/ r/ \* O+ Y9 Cwebapp webapp  =========|_|==============|___/=/_/_/_/<span style="color: rgba(0, 0, 0, 1)">
7 G! w( z+ S9 ?4 Nwebapp webapp  :: Spring Boot ::                (v2.</span><span style="color: rgba(128, 0, 128, 1)">4.2</span><span style="color: rgba(0, 0, 0, 1)">)
' D3 E3 B# a  j6 @" `webapp webapp6 {6 J2 N5 P+ v8 {
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); `) M, ?9 f" n5 ^4 H5 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)">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  b4 ]6 s2 U% [) p4 V# x! c& g0 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)- G' {, u6 |) 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)">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)">]2 \$ w4 a* Y- m
webapp webapp </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">53.200</span><span style="color: rgba(0, 0, 0, 1)"> [INFO ] [main] [org.apache.catalina.core.StandardService] Starting service [Tomcat]" _, K+ k: ^; S) i, r2 ~1 j  {, B' z' 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.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)">]
* a9 A* c: \. W  f+ Z, iwebapp webapp </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">53.324</span> [INFO ] [main] [org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/<span style="color: rgba(0, 0, 0, 1)">]] Initializing Spring embedded WebApplicationContext
2 s( ^$ z! D9 ]/ u5 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.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, p* N0 f9 s! 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)">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)">& F& m0 i- P# s' U) b" K. W' x' {+ 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)">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 ]; Y% [& e; O6 z
webapp webapp </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">54.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)">]
) x2 A2 c3 f% L4 L7 Bwebapp 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)">* q$ X$ W) t5 m2 [( 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)">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>
9 N- [  j1 W8 Z! r+ i. R1 G4 Y. x</div>
2 j' R: R0 B6 \  w' ?<p>&nbsp;</p>9 h) K- o! ]4 [5 ^, q+ T. L
回复

使用道具 举报

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

本版积分规则

手机版|飞雪团队

GMT+8, 2025-7-17 08:34 , Processed in 0.081216 second(s), 22 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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