飞雪团队

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

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

[复制链接]

8920

主题

9008

帖子

2万

积分

管理员

Rank: 9Rank: 9Rank: 9

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

, S, m- \  ?3 Z<p>kubectl作为我们主要的操作K8S的工具,其具备非常丰富的功能,但是如果不经过打磨,使用起来还是存在诸多不便,今天我们来看看如何将我们的kubectl打磨的更加易用。</p>
$ j8 P9 V3 N2 E  ^+ B5 l) s7 b<p>&nbsp;</p>1 W" Z) {! W  W( y" s1 J, j/ T+ S/ n
<p>一、命令自动补全</p>
# F8 Z4 e. B1 U4 K& T<p>kubectl中提供非常多的命令,如果每一次都要手动一个字符一个字符的敲未免太累了,那么如何配置自动补全呢?这里以ubuntu系统为例:</p>' w* J4 e- i. B# c! o
<p>1、安装auto-completion工具</p>
- Y2 |  q% U% q7 q1 y' H<div class="cnblogs_code">* @! r8 Q: l/ V3 Z; y. E
<pre>$ <span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> apt update
9 @' l; E  ~1 t2 P/ Z1 s  cHit:</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>
; m- k3 ^& K) y$ LHit:<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>, _( H) S. E$ U4 t4 A
Hit:<span style="color: rgba(128, 0, 128, 1)">3</span> http:<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">archive.ubuntu.com/ubuntu bionic-updates InRelease</span>
, v5 K5 s3 Q; h6 UHit:<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>9 b9 k$ ]  Y* W( u
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>4 s4 N7 I: a6 r, c# l
<span style="color: rgba(0, 0, 0, 1)">Reading package lists... Done
6 O4 ~( r5 H) X9 x$ S/ Z3 e0 XBuilding dependency tree- x" o( g' ^! Y4 r$ ^
Reading state information... Done- @( A/ n! C2 p% l% j# O. y
</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.
9 h7 ~0 l- v: N6 Z5 c; y% ?% b6 Z$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span> apt <span style="color: rgba(0, 0, 255, 1)">install</span> bash-<span style="color: rgba(0, 0, 0, 1)">completion. Z, b# [& i3 E# ~
Reading package lists... Done0 C- _% d% i; X7 ]2 g( r
Building dependency tree
; f7 T( `! [# n& I8 hReading state information... Done
( }" ?# R; [! O) zbash</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).
7 U2 \& Q0 n. g3 D' s) }7 v</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>' A9 [) s. d# [! [" ]2 ~7 x. K  L
</div>
( e( e$ ^: \' R* E<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>
5 |9 \' B/ n. ~6 G1 c<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>
4 G/ C$ q6 |; u8 P4 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>3 f2 U) F7 r# K
<div class="cnblogs_code">: p9 f, {2 E' a# }7 i) Y
<pre>source &lt;<span style="color: rgba(0, 0, 0, 1)">(kubectl completion bash)
4 d; A# L9 t- a7 b+ T2 ]</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>  B  |$ g9 K, }) x
</div>
" b& P' s" e( h2 W( x; q+ h<p><strong>Zsh</strong>:</p>" X; O/ e* V2 p) i$ T/ i7 v
<div class="cnblogs_code">
' W( s& c& o  T- i* B: N9 G$ g6 e0 }<pre>source &lt;<span style="color: rgba(0, 0, 0, 1)">(kubectl completion zsh)
' h* e) F! u- w2 S- I' ^( c  r8 G; W</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>7 H( s% D0 d2 w' a3 H  @
</div>9 W8 A! ?/ L" R4 _- ^  k9 q& D) x, v
<p>配置后就可以通过Tab键自动补全命令啦!</p>
" S: N& \1 |- L! \. z<p>&nbsp;</p>" L1 ]' ^$ k& K2 \5 [; ?: x
<p>二、配置kubectl别名</p>) w. x7 q  w9 V/ s5 u8 u
<p>我们可以通过设置别名简化kubectl命令,编辑.bashrc文件,添加如下内容:</p>
* k6 ?# P) J2 Q9 f/ |<div class="cnblogs_code">1 k& X. p5 ^1 o! w
<pre>alias <span style="color: rgba(0, 0, 255, 1)">sudo</span>=<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">sudo </span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">
' }8 r0 S$ C' |3 M$ Z; j( X- Palias k</span>=<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">kubectl</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">
3 B' e( S+ ~* Z7 |8 s- i6 Qalias 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)">
! a& e# c: P. }: \! kalias 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)">
( Z8 O' l* ~0 k( a/ \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)">* h, [0 V+ Y2 ?- R% Q& N" N
alias kg</span>=<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">kubectl get</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">' J2 a% Q$ s9 h# D8 J# U7 e
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>
* Q$ R# |7 A) _' M</div>0 a- k6 ^$ M* Z$ [8 \
<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>1 B/ I4 I; Q% }9 p3 u7 @8 U: u$ ?; Y  ~2 Y
<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># ], j" g. k  V
<div class="cnblogs_code">* @; n$ _6 N6 U. ?; x. L- h
<pre>$ <span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> ka webapp_pod.yaml. }1 @3 m3 c. S9 M! y
pod</span>/<span style="color: rgba(0, 0, 0, 1)">webapp created. W; z/ ^; i+ W. v1 ^. Q0 ^
$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> kg pods: a" s1 @, W6 C% m0 z* q6 h  D' `
NAME     READY   STATUS              RESTARTS   AGE8 b, ^0 x4 F! [+ d, e8 y2 x
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
+ q) K9 K% M+ y2 z% W$ W$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> kd pod webapp
. h% S, K; E- w6 ~3 v+ uName:         webapp
. A  B0 K3 B( [) O; F, GNamespace:    default
6 v. m6 G2 `& p0 V) F% H2 lPriority:     </span><span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">
' g2 Y+ S/ G0 Z# p& g/ nNode:         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)">( E/ U( c* A; O8 ?
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)">
+ [, D4 [- `) e( kLabels:       app</span>=<span style="color: rgba(0, 0, 0, 1)">webapp
9 g4 P8 ^) H2 _; S1 S% c# YAnnotations:  </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">
  e  l# B7 R0 _Status:       Running. p  r+ ~8 S1 |, E, r& s: Y! w- O
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)">! w: n/ ~- n0 y4 n
IPs:
! s6 d1 m; {: l0 d( l; j  IP:  </span><span style="color: rgba(128, 0, 128, 1)">172.17</span>.<span style="color: rgba(128, 0, 128, 1)">0.6</span><span style="color: rgba(0, 0, 0, 1)">
& }: Y! a6 J! J0 _: MContainers:
! n  L; K% V# J" }) R  webapp:9 W9 i9 L5 ^1 ?5 K) }
    Container ID:   docker:</span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">d9ddf9dd47de12b53f2119bf75df6706bee2e7711509638ad52adc9addeda704</span>
1 w6 @& b7 y, B+ }5 S. I    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)">: w+ f) W9 v! N# F6 E# v" V+ _% v
    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>  D/ q$ ~5 {  y
    Port:           <span style="color: rgba(128, 0, 128, 1)">5000</span>/<span style="color: rgba(0, 0, 0, 1)">TCP
: I3 n  k: K0 T% F    Host Port:      </span><span style="color: rgba(128, 0, 128, 1)">0</span>/<span style="color: rgba(0, 0, 0, 1)">TCP
0 X3 ^6 X* E8 B( N% v. i- S    State:          Running2 ?9 G# T1 I4 r* [: `: g  x0 `
      Started:      Wed, </span><span style="color: rgba(128, 0, 128, 1)">09</span> Feb <span style="color: rgba(128, 0, 128, 1)">2022</span> <span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">46</span> +<span style="color: rgba(128, 0, 128, 1)">0000</span><span style="color: rgba(0, 0, 0, 1)">
9 s6 e) ]1 Z9 J2 h    Ready:          True% K& g5 y( ~/ H4 ~3 Q+ v! }3 L5 d
    Restart Count:  </span><span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">' v; \8 F6 o; b6 u+ S! C; T
    Environment:    </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">
& x4 I$ L' T0 }' U1 h9 q8 j" S    Mounts:
& ~; I9 o" S5 Q( D3 R      </span>/tmp from webapp-<span style="color: rgba(0, 0, 0, 1)">logs (rw)
' R6 p6 N% S: i9 p1 J      </span>/var/run/secrets/kubernetes.io/serviceaccount from default-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h (ro)
# c& K( u9 V& k3 Z3 o+ Q8 \  busybox:) T( I- u6 F8 i4 n1 J
    Container ID:  docker:</span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">6a6a35a628a782fc643af3dd49986bbc77c23de1ae4726bc521c77f61abbbf5d</span>' h1 b# O# x) @
<span style="color: rgba(0, 0, 0, 1)">    Image:         busybox
* V( {& ^( a' a5 T' s+ H    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>' p3 d/ n. E! N7 Z  ?' k0 L6 y
    Port:          &lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">
( y1 |& u; N1 h" M5 ^8 d9 T    Host Port:     </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">
$ ^4 G: t$ \% u$ k; n, d    Command:
. O/ K& M& s, U5 `: B8 ?9 ^      </span><span style="color: rgba(0, 0, 255, 1)">sh</span>0 c0 }/ g& ~* K1 P/ `
      -<span style="color: rgba(0, 0, 0, 1)">c
& |0 \) j; [# U/ G# m$ u4 P      </span><span style="color: rgba(0, 0, 255, 1)">tail</span> -f /logs/<span style="color: rgba(0, 0, 0, 1)">log.out; z; H# H% D8 X1 Q9 f+ r2 g
    State:          Running
& Q5 B5 N# Q6 k8 W# 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)">
# M+ v. q( f3 X" u# p    Ready:          True
: i8 }: S% v8 o5 h    Restart Count:  </span><span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">
3 n/ N! G+ u5 n: h5 f& e    Environment:    </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">
3 `3 h- ^% g; n* D" v2 o5 l    Mounts:+ n& D1 [  O  u6 H0 A, r
      </span>/logs from webapp-<span style="color: rgba(0, 0, 0, 1)">logs (rw)
5 [9 w% m: U- O1 T0 P* _* [# q# n: q6 V      </span>/var/run/secrets/kubernetes.io/serviceaccount from default-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h (ro)5 S9 V: l! |$ A( Z2 U/ D
Conditions:! V( F$ q$ D  d2 E
  Type              Status" |* ?, h- t& J0 i/ d
  Initialized       True1 v" j- i0 h" `/ Z' q1 V2 u- n
  Ready             True3 r! a! l* F* c- r
  ContainersReady   True
5 Q- D7 M+ B1 Z) Z% H  PodScheduled      True, T* Z3 {' \2 f0 G* V
Volumes:
, R( X% {* b# K2 Y: e( w  webapp</span>-<span style="color: rgba(0, 0, 0, 1)">logs:
3 O8 h6 C  k& \5 s    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>
" Z1 d* J$ e: g- G9 S<span style="color: rgba(0, 0, 0, 1)">    Medium:
# S  u4 V: v. h5 f2 K% j    SizeLimit:  </span>&lt;unset&gt;<span style="color: rgba(0, 0, 0, 1)"># O6 D7 y9 q5 u; q2 }4 x" X* B
  default</span>-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h:! x# C- G$ \# |
    Type:        Secret (a volume populated by a Secret)# Y: [/ V1 }' d# Y5 P" A+ c
    SecretName:  default</span>-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h
5 P! [( p+ l) a! ~+ P* G" f    Optional:    </span><span style="color: rgba(0, 0, 255, 1)">false</span><span style="color: rgba(0, 0, 0, 1)">
$ D/ I& s- y  g+ J9 NQoS Class:       BestEffort
5 W6 Z7 @2 u7 ~3 X0 j3 C! oNode</span>-Selectors:  &lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">
) R) @' Z9 @) Y! iTolerations:     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)"> 300s0 y5 {9 I( D9 ^+ g" |0 i
                 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
, u( A7 W7 w) C. c8 GEvents:4 k- Y0 |+ ?7 x7 [" \- h
  Type    Reason     Age    From               Message
' M' f& a; d8 n; V% H1 m  </span>----    ------     ----   ----               -------<span style="color: rgba(0, 0, 0, 1)">1 ~, I; v0 @% [) ^0 K$ \
  Normal  Scheduled  2m23s  default</span>-scheduler  Successfully assigned default/<span style="color: rgba(0, 0, 0, 1)">webapp to ayato1 p( f8 F- v/ H3 a# r
  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
/ @% z# `$ g* w3 ^. r  Normal  Created    2m21s  kubelet            Created container webapp: O5 t7 z: P) s( p1 [1 O( o
  Normal  Started    2m21s  kubelet            Started container webapp
' F% o* s. b( ]" N  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)">
3 u+ B) ~; I! ], K. x  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
" s5 h/ d4 ?3 U" n  Normal  Created    15s    kubelet            Created container busybox
) A1 f+ p) p' V' k  Normal  Started    14s    kubelet            Started container busybox</span></pre>
  o. b; t7 @+ l</div>
* T- t. P* ?5 F) h( A+ u" t<p>真的是飞一般的感觉!!!</p>  H; a/ t- @5 s
<p>&nbsp;</p>' e6 v: @" Q' R& O
<p>三、Context和Namespace切换</p>
( c% U  `- j0 w+ \3 b<p>我们在公司的容器平台上使用kubectl时,经常需要切换context和namespace,导致命令非常繁琐,那有没有简便的方式呢?—— kubectx</p>) f( m5 F# B3 C! a. w
<p>kubectx安装</p>; ~: C# V0 f: m- k
<div class="cnblogs_code">
' w$ J* h, m4 e+ F; y<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>
3 N( Z$ u- j2 H/ iCloning 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)">...! |9 X* O- @  l& L& z- {: f  x
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)">.: Y: X6 K' ]4 Z4 S' O9 Y2 ]) I
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)">.
" X2 w2 P$ X& A. n) Fremote: 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)">.# s$ m# x/ N% H6 f2 }* h- G
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)">4 T: h8 k) L" F5 A$ r
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)">.5 ^2 \: f* L! s4 I; u
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)">.
! T! V! x1 U. X, H. S; c. Q$ </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
( G: ^8 ]! D: C! c; K: E1 v$ </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>
- l& ]# d; l( [' G2 }  P0 c</div>
( W! Q$ Y. E& o9 K2 x<p>我们来看一下效果:</p>7 j4 x; m5 q* s) B* X' E8 K
<div class="cnblogs_code">
6 z1 s6 x; N8 H<pre>$ <span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ctx
/ Y# z* `7 ?+ N% O; G- l0 o. ominikube( w1 @4 z6 i1 f
$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ctx minikube% H& [5 H5 t) Q# h) Y2 S& \
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)">.3 A# z* {  u2 m& V  ]* K, k
$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ns
- {7 v& e" M& D; ^( e7 Fdefault6 [: O' ^2 U% J
kube</span>-node-<span style="color: rgba(0, 0, 0, 1)">lease: l, I3 k9 [+ A: C0 u$ \8 q9 k
kube</span>-<span style="color: rgba(0, 0, 0, 1)">public
; m6 ^$ g" r2 w) [kube</span>-<span style="color: rgba(0, 0, 0, 1)">system
# F. u; Z  h$ W- R7 y2 Ckubernetes</span>-<span style="color: rgba(0, 0, 0, 1)">dashboard& ~- `- A+ e) w  \+ e* o1 {
$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span> k ns kube-<span style="color: rgba(0, 0, 0, 1)">public- ^3 h1 J1 D9 C. N# G( t7 Q6 u
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.
/ q8 {1 g! \9 ZActive 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)">." D5 A/ E! M" f/ x
$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ns default2 [! u4 ?% F# p6 H
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./ m  a% J, Q2 }( c" i
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>  q4 f# g7 Q1 ~
</div>$ a9 {3 i5 u" P7 d
<p>&nbsp;</p>3 P8 w7 t& c& W- i
<p>四、跟踪查看多个Pod的日志</p>% X4 ?# N5 t* }$ _$ j( e
<p>我们一般使用kubectl logs命令查看Pod日志,但是它不能通过-f参数同时跟踪查看多个Pod日志,这就不方便了,毕竟实际生产环境中每个服务都会有多个Pod,这时我们可以使用stern这个工具,它具备如下能力:</p>2 z! V5 H' f" `* {7 m3 U
<ul class="list-paddingleft-2">
( G" Y. C- B. ^2 x<li>
7 x- D1 ]! m8 j6 Q, D<p>允许使用正则表达式来选择需要查看的PodName</p>
; _$ P: G$ J' N2 c4 }</li>1 l* E$ s- d7 j& Q$ k0 s" M
<li>
0 `" E% |* v; |+ a% U, U<p>为不同 Pod 的日志展示不同的颜色</p>
+ B% [5 Y, t% w: W; K' O; A</li>
7 G: g+ I# _, X; h<li>6 C* G$ x: u- Y: f% s+ J; N1 D! }
<p>跟踪日志过程中假如有符合规则的新 Pod 被创建, 那么会自动添加到输出中</p>) T, }/ G9 x; a
</li>
+ T0 ?: W4 f- a$ d6 g8 t  t</ul>
$ G: d/ Q5 L: a* e" u/ H1 @; m<p>首先安装stern(下载stern时可能较慢可以多试几次):</p>
4 Q# N1 u! u( U( p+ D( S& G<div class="cnblogs_code">8 Z! U1 N) q9 v) _
<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>' r1 Y, u0 l; o' i6 ^! M
<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>
) S/ [, J9 h$ G+ B, A<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>
1 S% X0 q$ ~5 H( b% z  t( E5 Q</div>
: t" L  ~1 a9 d2 l/ f0 J<p>安装完毕后让我一起感受一下stern的魅力吧,我的Pod里面有两个容器:webapp和busybox,如果使用kubectl logs 还得指定具体的容器,而使用stern就没有这样的限制。</p>, x8 c7 s- _; K$ ^2 t: a. Y
<div class="cnblogs_code">
6 H9 c- n. }2 R: q<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)"> .
# q, ~7 M$ p' w7 P6 r* C/ U* e" l</span>+<span style="color: rgba(0, 0, 0, 1)"> webapp › busybox- h' l: Y/ J3 h& x
</span>+<span style="color: rgba(0, 0, 0, 1)"> webapp › webapp4 X  r6 A. b, C3 X; d
webapp busybox </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">53.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)">]0 {3 z' _6 @. o- V- J) ?$ X5 w
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]
9 }; B$ u- K' k" y0 W2 D6 I4 Zwebapp busybox </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">53.201</span> [INFO ] [main] [org.apache.catalina.core.StandardEngine] Starting Servlet engine: [Apache Tomcat/<span style="color: rgba(128, 0, 128, 1)">9.0</span>.<span style="color: rgba(128, 0, 128, 1)">41</span><span style="color: rgba(0, 0, 0, 1)">]3 N2 ?' a, i8 o( C" B. F5 s
webapp busybox </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">53.324</span> [INFO ] [main] [org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/<span style="color: rgba(0, 0, 0, 1)">]] Initializing Spring embedded WebApplicationContext
) f) k) o2 Y1 _0 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.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; X9 r/ |0 q% s8 v1 ]
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)">4 [1 a2 }4 J1 G3 e2 r3 {$ M1 ^
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 q8 Q, L2 v- z% {9 M& I, n+ H1 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)">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)">]/ P# r4 u" @8 Y" z5 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)">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)">7 ]1 F' ^- |& i+ 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)">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)">)1 ~9 V% d/ u' b: U& ?( x
webapp webapp
" V' Z4 l& l3 I5 Hwebapp webapp   .   ____          _            __ _ _- j; }) R* ~+ y
webapp webapp  </span>/\\ / ___<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">_ __ _ _(_)_ __  __ _ \ \ \ \</span>9 v* Q: [0 X2 |# A, X5 B
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>) K1 e. P) F; ?. c" Q5 o
webapp webapp  \\/  ___)| |_)| | | | | || (_| |<span style="color: rgba(0, 0, 0, 1)">  ) ) ) )! N% }9 d1 b) r2 V; b
webapp webapp   </span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">  |____| .__|_| |_|_| |_\__, | / / / /</span>) W5 t1 T7 _# ~$ P) P, Y6 O: h( A$ G3 }
webapp webapp  =========|_|==============|___/=/_/_/_/<span style="color: rgba(0, 0, 0, 1)">
: u! E8 w2 c$ C! ?' 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)">)5 V5 n& g' f3 n/ H& C2 p; C
webapp webapp4 y' B& p! g. f& E! e
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)" d9 t% f$ g; b7 ^
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
  L4 s, b9 W* p* l+ wwebapp 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)
# C; {/ t. Z( 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)">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)">]
: W6 j: c/ ]* V1 A/ n" i0 M6 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.200</span><span style="color: rgba(0, 0, 0, 1)"> [INFO ] [main] [org.apache.catalina.core.StandardService] Starting service [Tomcat]
) U: w, }; O  V* K9 \( v2 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.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)">]# Y0 m4 r4 P- J  C1 f- [% L4 `
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
% h4 s$ V! R0 U, D6 p, _5 Dwebapp 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( [5 p. c' J! e  y
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)"># C9 `( v( ]0 D. u; d: 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.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)
& I7 p/ t1 f+ 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)">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)">]
, c' q; l; a0 z9 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)">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)">: q9 R5 ?  s. 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.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>  Q$ o0 V8 A. [7 E6 @5 I; L
</div>% Z1 @: I  ]6 e, p- z2 k
<p>&nbsp;</p>! ^% I; `$ ~/ g( H0 @
回复

使用道具 举报

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

本版积分规则

手机版|飞雪团队

GMT+8, 2026-7-5 00:26 , Processed in 0.137543 second(s), 22 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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