飞雪团队

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

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

[复制链接]

6855

主题

6943

帖子

2万

积分

管理员

Rank: 9Rank: 9Rank: 9

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

* T1 t. r6 x  ~6 ?<p>kubectl作为我们主要的操作K8S的工具,其具备非常丰富的功能,但是如果不经过打磨,使用起来还是存在诸多不便,今天我们来看看如何将我们的kubectl打磨的更加易用。</p># g8 [3 F1 X/ J
<p>&nbsp;</p>4 H0 H0 m  @/ h# S
<p>一、命令自动补全</p>
; C; ]0 i# B" X5 _/ r! j" A% Z. [4 i<p>kubectl中提供非常多的命令,如果每一次都要手动一个字符一个字符的敲未免太累了,那么如何配置自动补全呢?这里以ubuntu系统为例:</p>3 ^8 x$ e  P  N6 t- j* c! m
<p>1、安装auto-completion工具</p>
! [+ [# Y! O. i* k<div class="cnblogs_code">% E& |) R* ?) A- A. C% j1 o
<pre>$ <span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> apt update8 s  ^& B3 f" R. v! 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>
! W2 g" P0 Q& [# U1 kHit:<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>
  F% D- j: r( @" ]* R- P1 J$ }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>6 q  ?! z/ d# ?6 c
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>
! a6 h! m* H; H  }3 EHit:<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 n, j  X9 ]5 Q$ c, Y<span style="color: rgba(0, 0, 0, 1)">Reading package lists... Done
, K& \+ t5 p; |$ X4 MBuilding dependency tree' @) M" t% s) X4 a3 H: m4 V0 B
Reading state information... Done
) S7 Y! P% b+ C- D6 Y/ r+ S# ~  D</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.
" |! f1 i& a2 w1 s2 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)">completion3 M# a7 Q9 M$ _# O; Y1 e& g
Reading package lists... Done
+ {" O- z8 o' Z2 H3 m, E/ }, jBuilding dependency tree8 F5 `2 U, u- h8 d7 @$ E
Reading state information... Done7 f& t1 D5 j3 v
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)." p1 R& j. s' F. g, @; S
</span><span style="color: rgba(128, 0, 128, 1)">0</span> upgraded, <span style="color: rgba(128, 0, 128, 1)">0</span> newly installed, <span style="color: rgba(128, 0, 128, 1)">0</span> to remove and <span style="color: rgba(128, 0, 128, 1)">144</span> not upgraded.</pre>
9 z5 A* a2 @# h% c! L4 p</div>
4 W) U! N5 L: }6 k<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>
9 n2 ]; x) D; F2 Z& l<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>7 ]) n$ J9 |/ `
<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>& y" B- p' S$ e! H
<div class="cnblogs_code">
2 D$ n, f' |/ ^/ B<pre>source &lt;<span style="color: rgba(0, 0, 0, 1)">(kubectl completion bash)& o- q$ Q8 y8 L  @, _
</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>  P6 F1 j2 J4 z0 V
</div>  i6 c) V! ^$ k
<p><strong>Zsh</strong>:</p>2 U: Z" W$ |# r: a! ?6 B( b
<div class="cnblogs_code">
1 ~. M& Z2 \, R* M<pre>source &lt;<span style="color: rgba(0, 0, 0, 1)">(kubectl completion zsh)% ^4 Y9 d5 N8 w& o: l6 E
</span><span style="color: rgba(0, 0, 255, 1)">echo</span> <span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">[[ $commands[kubectl] ]] &amp;&amp; source &lt;(kubectl completion zsh)</span><span style="color: rgba(128, 0, 0, 1)">"</span> &gt;&gt; ~/.zshrc</pre>
; B. ]7 M+ O5 m+ T8 H</div>$ Z7 E$ s7 k3 r3 n9 `; J" o7 T
<p>配置后就可以通过Tab键自动补全命令啦!</p>. G, r) t5 i" `3 F: v
<p>&nbsp;</p>
3 o$ p' ^! k. a% t' l+ R<p>二、配置kubectl别名</p>' Z9 w* z; `& O5 F( z1 \
<p>我们可以通过设置别名简化kubectl命令,编辑.bashrc文件,添加如下内容:</p>7 |) x) t7 {' k" A
<div class="cnblogs_code">
6 i0 r5 @: S  `8 p<pre>alias <span style="color: rgba(0, 0, 255, 1)">sudo</span>=<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">sudo </span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">
1 c' v' b1 E7 U# `: h( R5 ealias 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)">6 Z  G; ~1 H1 }- w( H
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)">
1 ]4 q: `: m1 G5 W. j1 V" ]/ F- Falias 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)">* i. i* l+ y9 K, z
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)">
; N2 D; {2 v" g/ }& K  b' ?& Q- x$ M4 Ealias 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)">; f% Z- ~, J! c6 x8 _
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>9 G# S5 g/ a# B5 B2 J& k  q
</div>9 o- E  e3 D3 k
<p><span class="js_darkmode__4" data-darkmode-color-16446330660319="rgb(0, 104, 255)" data-darkmode-original-color-16446330660319="#fff|rgb(0, 82, 255)" data-style="color: rgb(0, 82, 255);"><strong data-darkmode-color-16446330660319="rgb(0, 104, 255)" data-darkmode-original-color-16446330660319="#fff|rgb(0, 82, 255)">PS:alias sudo是为了解决sudo下别名不可用问题</strong><br></span></p>) q' t. R, O3 o8 g
<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>
& K5 v3 a! p' G9 ]9 M0 B/ k* l<div class="cnblogs_code">
2 d9 E& f- u- F& a( y" ]6 N<pre>$ <span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> ka webapp_pod.yaml
5 x* ?9 Z" s$ b& zpod</span>/<span style="color: rgba(0, 0, 0, 1)">webapp created
! Z! A; ~$ Q# B8 p$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> kg pods9 S- k( z" U4 `0 L/ i7 b; p
NAME     READY   STATUS              RESTARTS   AGE
- m$ f% g/ M' Ywebapp   </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; J+ V! e1 m. o$ a( N9 [4 i- D
$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> kd pod webapp
: u0 N# _6 `! w: V4 IName:         webapp
2 |! Q9 o& a. o* v( s# t* ]Namespace:    default4 S3 V  ^2 }5 V- h( S
Priority:     </span><span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">
9 y. H6 d  A9 k& kNode:         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)">
  r6 ~8 N0 C; FStart 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)">
/ l7 ]5 W1 ?& p- `$ S- iLabels:       app</span>=<span style="color: rgba(0, 0, 0, 1)">webapp7 H* L$ ~, D( q( o* r- Z* }( d
Annotations:  </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">% g7 n8 w) R9 `) A" u5 T- E
Status:       Running
4 i6 o5 C, A! y$ a" V. l) K+ T4 }: FIP:           </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. ~8 E# b$ B0 Q3 fIPs:
& Q) n) f" Z' b$ 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)">
# H& c, y4 L" R- _4 M5 G1 z- }0 T) |Containers:
) [" M0 @9 G" X9 E1 }/ C, P  webapp:. t) C, i- ^) a9 [2 R
    Container ID:   docker:</span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">d9ddf9dd47de12b53f2119bf75df6706bee2e7711509638ad52adc9addeda704</span>& T4 }! J) W9 f
    Image:          <span style="color: rgba(128, 0, 128, 1)">172.16</span>.<span style="color: rgba(128, 0, 128, 1)">194.135</span>:<span style="color: rgba(128, 0, 128, 1)">5000</span>/webapp:<span style="color: rgba(128, 0, 128, 1)">1.0</span><span style="color: rgba(0, 0, 0, 1)">  A  k* \/ c4 C+ n
    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>
3 ]1 w+ [+ j! w/ Z0 g    Port:           <span style="color: rgba(128, 0, 128, 1)">5000</span>/<span style="color: rgba(0, 0, 0, 1)">TCP
2 I0 Z# `: L; [7 @* o+ u0 c% A) y0 O    Host Port:      </span><span style="color: rgba(128, 0, 128, 1)">0</span>/<span style="color: rgba(0, 0, 0, 1)">TCP: ]# E5 N8 e  o5 b6 ~2 z* T
    State:          Running
, m( b6 R7 P8 V9 }! N6 v      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)">% s. b$ t! @+ E# V$ T2 C; n+ b
    Ready:          True& I8 P+ j  w3 H% `$ W
    Restart Count:  </span><span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">. N' K; j: G: F& Y. y3 L
    Environment:    </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">
# A6 u' j+ L, [% r7 W+ E# w    Mounts:5 N( F2 k8 e8 V) Y
      </span>/tmp from webapp-<span style="color: rgba(0, 0, 0, 1)">logs (rw)# O! U3 V3 [7 p- g8 O. Z
      </span>/var/run/secrets/kubernetes.io/serviceaccount from default-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h (ro)8 {# o' W) z2 d! B: |: E1 _' k
  busybox:
$ T, t# H2 `0 ^/ W9 a2 p* h" W0 I    Container ID:  docker:</span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">6a6a35a628a782fc643af3dd49986bbc77c23de1ae4726bc521c77f61abbbf5d</span>' Z5 h; b3 `# ^0 Q! U+ W. C2 }. X6 K
<span style="color: rgba(0, 0, 0, 1)">    Image:         busybox
& D7 q% j% j* v    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>
& v! u! ^. o4 F, o' d5 W+ H    Port:          &lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">, W. I9 D+ n1 u3 r0 }$ H: p3 s
    Host Port:     </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">
! V2 v/ r! l+ S0 {8 P5 R    Command:+ w/ B- l4 E+ n5 F! ]: h- s
      </span><span style="color: rgba(0, 0, 255, 1)">sh</span>. A. k4 B+ V3 w. d% D
      -<span style="color: rgba(0, 0, 0, 1)">c  P( V# G# \' J
      </span><span style="color: rgba(0, 0, 255, 1)">tail</span> -f /logs/<span style="color: rgba(0, 0, 0, 1)">log.out
8 X4 S3 \! b  P# f3 m) R    State:          Running4 M8 G2 T/ u# I5 p
      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)">! V+ P4 O% p( }  U6 F* n" r" O# W
    Ready:          True  p# y) F( G; s9 x8 o# q) p; x
    Restart Count:  </span><span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">2 q- |" \/ A0 {* S, @
    Environment:    </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">/ n( _! w2 K* k
    Mounts:( J* o! ]* r' M' k% g
      </span>/logs from webapp-<span style="color: rgba(0, 0, 0, 1)">logs (rw)
) f* b$ s; ?/ F  g      </span>/var/run/secrets/kubernetes.io/serviceaccount from default-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h (ro)
" K1 g4 }0 x8 T8 T; ~: d' }* V8 K/ FConditions:8 A: P; d* G& V6 U6 a% u6 n2 O
  Type              Status4 Q. y7 g( X* D3 |4 ]; H
  Initialized       True
9 Y' o& P! C& j! e( E: ^2 B* i5 q  Ready             True) {, O" G! Y% f6 O/ \$ ^: V
  ContainersReady   True& q) i! n" e3 ^3 U9 L0 |0 H
  PodScheduled      True+ `9 x) B2 D0 b
Volumes:% R" q) Q! c  U$ U9 R! a# Z# q
  webapp</span>-<span style="color: rgba(0, 0, 0, 1)">logs:
  i! z) T. ]5 K( J    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>& O0 ?, ?$ }; P, s/ `! ^
<span style="color: rgba(0, 0, 0, 1)">    Medium:1 m/ B: v* t7 ^- g8 E
    SizeLimit:  </span>&lt;unset&gt;<span style="color: rgba(0, 0, 0, 1)">
5 o- ?7 s' E: _( J' j: e  default</span>-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h:5 N/ _. r& K# T1 {4 }
    Type:        Secret (a volume populated by a Secret). z" s( ]5 G# f( l
    SecretName:  default</span>-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h, d; k  _$ [! K" p- E! B& t
    Optional:    </span><span style="color: rgba(0, 0, 255, 1)">false</span><span style="color: rgba(0, 0, 0, 1)">! S: \8 V: i" _8 m. V7 \& j
QoS Class:       BestEffort
/ K8 A! ^. s9 A% ^0 \Node</span>-Selectors:  &lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">$ G& B+ s( g  @; Z( K; }7 O
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
, M& E4 x9 r' I8 X8 d% H. |0 f                 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
& l; E6 W+ u8 e) K) oEvents:
# ]+ U4 E: f: p; v' D- O  Type    Reason     Age    From               Message' B+ w( j1 W/ }/ w2 W
  </span>----    ------     ----   ----               -------<span style="color: rgba(0, 0, 0, 1)">
( L) }" B8 x" }' w3 w  Normal  Scheduled  2m23s  default</span>-scheduler  Successfully assigned default/<span style="color: rgba(0, 0, 0, 1)">webapp to ayato
% e& y6 R  ]' _5 J2 V  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  j4 @( n. a6 \* G% ^# n/ a5 e
  Normal  Created    2m21s  kubelet            Created container webapp3 e5 U9 ~5 r2 J. S/ u6 _: t
  Normal  Started    2m21s  kubelet            Started container webapp
( L3 Y0 {6 P2 S$ ~" i* g6 g* x2 d  Normal  Pulling    2m21s  kubelet            Pulling image </span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">busybox</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)">
4 v  [/ ~% k5 n7 w8 o  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' H7 k) B6 [/ O4 n4 ]$ H( x/ D) F
  Normal  Created    15s    kubelet            Created container busybox
$ i4 V+ r" l/ J  Normal  Started    14s    kubelet            Started container busybox</span></pre>) ]: D# D+ @8 y) a  M. Z
</div>$ `( z# A8 T7 C0 T4 z' L; g, m
<p>真的是飞一般的感觉!!!</p>
+ L1 E" r8 i0 I4 x* D& u0 X3 E<p>&nbsp;</p>+ G$ Q) s: t) |+ g: `
<p>三、Context和Namespace切换</p>( n1 V* h2 _& B5 u1 m* z
<p>我们在公司的容器平台上使用kubectl时,经常需要切换context和namespace,导致命令非常繁琐,那有没有简便的方式呢?—— kubectx</p>, P2 w# Y6 H1 e+ p# x. t; S$ v
<p>kubectx安装</p>& f1 d! W* w" q3 @; \5 F
<div class="cnblogs_code">- G, j# G6 U/ C6 c
<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>; s8 l- |9 ^. \" z0 P' 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)">...
% n% s7 X/ x, ~. b7 @( v. B% ~7 sremote: 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)">.1 p( X7 V. X0 R1 i1 b
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)">.
8 f0 p* |# A, M, f/ G9 R  Qremote: 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)">.
' Q* \% v# R$ V+ a- aremote: 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)">5 b( R& ?3 }4 s! E, h; j5 o
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)">.+ |0 I/ e6 R% ?" o" s# 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)">.
4 x6 h, q8 t* c+ _0 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/kubens /usr/local/bin/kubectl-<span style="color: rgba(0, 0, 0, 1)">ns
2 V9 D& t2 u. D, `- m" 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>1 ~- e: H) {8 W* r
</div>
) a0 ~2 A' B% H. ^, U! [. C& @<p>我们来看一下效果:</p>
8 a) L0 i+ R1 _% ?  s7 s<div class="cnblogs_code">
* X3 [9 h- d* ]<pre>$ <span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ctx
1 n0 Y( a! x4 R; Yminikube
" e$ `. Z  C2 K+ W" R0 G9 _* J$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ctx minikube
& k- y1 X1 b" k! m: G- d1 }1 R7 ^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)">.
) @0 k2 S, l. [# w( d) w3 c$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ns* Q8 \% T9 V* I' h( c3 l
default
3 p' |/ e- R+ [1 a% q/ lkube</span>-node-<span style="color: rgba(0, 0, 0, 1)">lease
1 L: `) W# T; j. T: X2 a( X1 bkube</span>-<span style="color: rgba(0, 0, 0, 1)">public6 m( g* O4 I/ S' o3 ~) t. y3 x- L
kube</span>-<span style="color: rgba(0, 0, 0, 1)">system
2 U) [7 r% B8 B. R8 a  hkubernetes</span>-<span style="color: rgba(0, 0, 0, 1)">dashboard, n5 y: @0 R5 y' O
$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span> k ns kube-<span style="color: rgba(0, 0, 0, 1)">public
! H  J9 \. O7 _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.
% r7 D$ z9 L2 `0 jActive 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)">.  z5 H# t9 E6 f6 |4 K& n
$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ns default
6 M6 c1 S' F6 F% a0 eContext </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.+ ^* {6 A7 |6 s
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>: x/ r+ e0 \. I
</div>: g: Y% r' j/ ^9 E. z7 b% \- n9 X
<p>&nbsp;</p>
- c* Q" K9 K* O5 b/ |<p>四、跟踪查看多个Pod的日志</p>
9 z% E" R4 u; v- w9 n+ W$ \<p>我们一般使用kubectl logs命令查看Pod日志,但是它不能通过-f参数同时跟踪查看多个Pod日志,这就不方便了,毕竟实际生产环境中每个服务都会有多个Pod,这时我们可以使用stern这个工具,它具备如下能力:</p>" a* i8 k/ v% q# f7 R! _' j3 V
<ul class="list-paddingleft-2">9 O4 j+ d/ u* a6 V
<li>
% c. f9 y# \+ {8 ]: _<p>允许使用正则表达式来选择需要查看的PodName</p>
; A8 {; u0 v& T8 W! K8 x2 r& ]6 x</li>
( s' K1 l; w6 R- ]* q5 h1 E<li>' g9 O2 t4 I) S" ?2 T) O. J
<p>为不同 Pod 的日志展示不同的颜色</p>
! b. C) ?$ J! |4 j</li>
, I" q! c9 T# u$ p<li>; p% J/ V$ S$ v* K  k
<p>跟踪日志过程中假如有符合规则的新 Pod 被创建, 那么会自动添加到输出中</p>
8 d' M/ R4 q, X# x: q7 o& V( c</li>5 }1 d6 |1 N+ J8 |; X% ^
</ul>
' ?. Q2 h- l* l4 S<p>首先安装stern(下载stern时可能较慢可以多试几次):</p>
& v0 Q/ I- _; w* I5 A! u) @# n9 E<div class="cnblogs_code">
9 R& x: L0 N8 e<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>3 V. k+ P7 M5 g! p6 T* \1 `5 K
<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>
$ Q. E$ {* B3 l" o; d<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 a& g; P! g. `9 M: u% I3 d
</div>
. Y+ L- F! {/ G6 N) I<p>安装完毕后让我一起感受一下stern的魅力吧,我的Pod里面有两个容器:webapp和busybox,如果使用kubectl logs 还得指定具体的容器,而使用stern就没有这样的限制。</p>
% s, |  Y  z) _. g3 a<div class="cnblogs_code">
( J# a. V+ S3 |2 r# P9 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)"> .2 l! ], _2 W8 c8 a
</span>+<span style="color: rgba(0, 0, 0, 1)"> webapp › busybox  k3 p$ U1 A6 [5 l
</span>+<span style="color: rgba(0, 0, 0, 1)"> webapp › webapp2 `, @; p" f1 P0 d# S% h9 V
webapp busybox </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">53.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)">]
* b3 l1 ]! l. owebapp busybox </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">53.200</span><span style="color: rgba(0, 0, 0, 1)"> [INFO ] [main] [org.apache.catalina.core.StandardService] Starting service [Tomcat]
/ J6 U9 k. D, K. ewebapp 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)">]9 r' Z, c! s+ u7 C/ 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.324</span> [INFO ] [main] [org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/<span style="color: rgba(0, 0, 0, 1)">]] Initializing Spring embedded WebApplicationContext: }7 x& g- L4 f
webapp busybox </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">53.325</span> [INFO ] [main] [org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext] Root WebApplicationContext: initialization completed <span style="color: rgba(0, 0, 255, 1)">in</span> <span style="color: rgba(128, 0, 128, 1)">2952</span><span style="color: rgba(0, 0, 0, 1)"> ms  E* H( d" E6 h- C# U  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.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)">
) |6 D0 o7 }( m3 rwebapp 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 R1 ^  w' o. X$ T6 P/ 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)">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)">]
0 c5 m$ Z6 T( ^2 kwebapp 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)">- \( h2 M4 x! @& G8 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)">); W# q) a4 M3 S4 S9 k; H" ^* l' ]3 W
webapp webapp" i7 V. J+ S' X. _" ~
webapp webapp   .   ____          _            __ _ _, H3 O. Z, e9 W' |
webapp webapp  </span>/\\ / ___<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">_ __ _ _(_)_ __  __ _ \ \ \ \</span>
' _' `4 R& e- X* Hwebapp 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>
$ v& }2 F4 Q( Hwebapp webapp  \\/  ___)| |_)| | | | | || (_| |<span style="color: rgba(0, 0, 0, 1)">  ) ) ) )
' j3 ]  V8 u0 J7 G9 Uwebapp webapp   </span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">  |____| .__|_| |_|_| |_\__, | / / / /</span>
0 t- ~: W2 D6 Y7 t& Y8 H6 @8 Twebapp webapp  =========|_|==============|___/=/_/_/_/<span style="color: rgba(0, 0, 0, 1)">$ I+ `' ?- d* x1 A
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)">)
4 j# v1 B  G/ j- w; ?; jwebapp webapp; }4 S7 F# k" u. 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)">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). g+ C9 n# u9 q- `2 z4 O4 n" j
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
5 T) X2 p2 D; P- R2 Xwebapp 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* N7 l2 r( ~/ ?# 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)">]7 W  R5 E  `9 s0 U9 ]1 q  T+ 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.200</span><span style="color: rgba(0, 0, 0, 1)"> [INFO ] [main] [org.apache.catalina.core.StandardService] Starting service [Tomcat]
7 h/ j9 {$ z7 g4 lwebapp webapp </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">53.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)">]9 }1 a: W, \1 @, Z4 K6 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
% Z# {3 M; J: D: o0 H$ _% fwebapp 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  O8 Y. n! J7 d: d' L" y, j9 R
webapp webapp </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">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)">3 w" L) L, [$ r( \8 T+ o
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)
( \5 m4 t1 N9 ]9 k% a$ d; Y5 J' \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)">]
% a8 @# {8 A- f/ ]4 s( L! zwebapp webapp </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">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)">& z) N3 J" B/ 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.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>
+ T- j+ x: g: n8 `; G% B0 H</div>0 g  |4 R  f4 z9 a' Y) j
<p>&nbsp;</p>
; }4 l5 B& [( ^- Z- U
回复

使用道具 举报

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

本版积分规则

手机版|飞雪团队

GMT+8, 2025-7-2 08:13 , Processed in 0.068074 second(s), 21 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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