飞雪团队

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

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

[复制链接]

8879

主题

8967

帖子

2万

积分

管理员

Rank: 9Rank: 9Rank: 9

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

; A! s6 }- b) `% O) _<p>kubectl作为我们主要的操作K8S的工具,其具备非常丰富的功能,但是如果不经过打磨,使用起来还是存在诸多不便,今天我们来看看如何将我们的kubectl打磨的更加易用。</p>
* L! G0 C1 o% ]* X+ B3 I3 D<p>&nbsp;</p>
- w6 v; R. r! U# ~/ r<p>一、命令自动补全</p>7 ?7 o% J+ b1 f
<p>kubectl中提供非常多的命令,如果每一次都要手动一个字符一个字符的敲未免太累了,那么如何配置自动补全呢?这里以ubuntu系统为例:</p>
# J3 Z! b/ g; ?( K( {8 e% w<p>1、安装auto-completion工具</p>' h! `7 S9 @1 V6 v( Z# i( J
<div class="cnblogs_code">' h5 _2 J! ]: \, `7 ?
<pre>$ <span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> apt update
2 ^8 T* A2 E9 V/ yHit:</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>1 `5 s8 F  }, \6 T5 I) h
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>
; ^+ M2 N; q" Q7 n' g! IHit:<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># U, o; U/ U. Z) ]. z
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>
5 l+ ?4 J. d8 C; I3 I/ kHit:<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>
5 P8 f8 w, D; z! r, L+ D<span style="color: rgba(0, 0, 0, 1)">Reading package lists... Done
7 j5 G  [0 F, Q* p9 x+ h  Q* `Building dependency tree6 u& h3 ^& I/ {2 [, g* g
Reading state information... Done2 {! }2 e# r) p( j
</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.
% h! G' W9 C5 {* S3 ]" v0 a$ </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
, U2 u: C8 D! ]& U* L  cReading package lists... Done- u6 g' l! v1 v6 C- T4 d3 H0 G! @& \
Building dependency tree# b4 e% v% n, A2 z& _
Reading state information... Done: X8 D" G$ q( V+ g. H
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).* j* f# s3 N% q3 F& 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>2 n4 w+ v8 K7 P
</div>. j$ W6 S/ o  [) f9 [# J
<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>+ A# ~% a  ~- u' I
<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>
/ l2 P# i. h1 k' R, z# c2 Q<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>
! U  J  l3 Z$ a" Q( u<div class="cnblogs_code">7 `' ~( W9 A  _4 d9 k* V
<pre>source &lt;<span style="color: rgba(0, 0, 0, 1)">(kubectl completion bash)
3 D% [5 i$ c) ]</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>9 T1 V' i6 e' q+ c
</div>) s8 O3 x3 q+ T
<p><strong>Zsh</strong>:</p>
4 g! u0 q, I# C7 }- z' J/ _<div class="cnblogs_code">
8 M' f9 W* u0 V0 L% s8 ^<pre>source &lt;<span style="color: rgba(0, 0, 0, 1)">(kubectl completion zsh). s& M# C: W: w. y
</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 Q2 F+ v( C" y' ?  K+ N+ L1 u* n
</div>
& p- v/ \/ O6 i& m* Z9 B<p>配置后就可以通过Tab键自动补全命令啦!</p>- W! P/ k2 f% x% A/ N2 x
<p>&nbsp;</p>
; z8 a  L% J8 {8 w* B( s. F<p>二、配置kubectl别名</p>
4 ]0 N6 ?* d! F* k& `6 `<p>我们可以通过设置别名简化kubectl命令,编辑.bashrc文件,添加如下内容:</p># k; t  ~+ \' M$ H7 D
<div class="cnblogs_code">
# c$ s* O6 s- C% D# k% n) G1 Z1 H3 {' [<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)">2 E$ Z" P# x3 }  Q
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)">, J2 C; G: W0 Q; {3 k9 D! V" k9 C
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)">
7 M; F% J5 B- K! t/ e# d3 nalias 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)">
8 Z, i+ m; \' I0 `" c; X, A6 _% Q2 u# {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)">& `( J9 {  O# h) v2 ]+ e1 x
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)">
5 @% `& b$ b8 {+ }6 y8 g8 O7 ialias 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>
6 l# m, \) n7 ^" L</div>
% x0 {3 F5 J& O) e$ O1 @6 I* t1 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>
6 k8 q1 F6 r, e* ]<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>
' e+ L4 k1 B2 g, x- {8 h' o<div class="cnblogs_code">$ r5 M! r1 M5 B; F1 k
<pre>$ <span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> ka webapp_pod.yaml
" u  F0 Z! M1 H0 j. y, @: j7 mpod</span>/<span style="color: rgba(0, 0, 0, 1)">webapp created/ a* A& I7 S- P- k
$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> kg pods
+ O: P! J6 I8 l; o: ^# sNAME     READY   STATUS              RESTARTS   AGE
) T8 S( b( Q( E2 l8 Bwebapp   </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" W2 t/ Q  m8 X9 f: \( i
$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> kd pod webapp0 D3 e5 @: y  r3 T$ `% o+ N* g
Name:         webapp
! q+ ~* p+ C# U/ PNamespace:    default
9 l. u. e4 N  T4 {; cPriority:     </span><span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">
" v0 \# a) X, \- H; `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)">* I3 y+ O  p& H6 p
Start Time:   Wed, </span><span style="color: rgba(128, 0, 128, 1)">09</span> Feb <span style="color: rgba(128, 0, 128, 1)">2022</span> <span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">44</span> +<span style="color: rgba(128, 0, 128, 1)">0000</span><span style="color: rgba(0, 0, 0, 1)">
6 U2 J+ I- S5 D: v; G$ O2 {( mLabels:       app</span>=<span style="color: rgba(0, 0, 0, 1)">webapp! Z0 h" w' F( `$ {
Annotations:  </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">
- s5 ^3 y% g& n, E/ _Status:       Running# ]% b& D2 g$ d: ?4 d
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)">. W3 V. D4 e+ k" N# ^
IPs:
" [5 s: M/ o, Z  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)">" s6 I. w/ E' F$ a
Containers:1 i) P, g, a) g7 b( A& v+ J  u
  webapp:
- z) Z- K" H) n! c/ T. ^    Container ID:   docker:</span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">d9ddf9dd47de12b53f2119bf75df6706bee2e7711509638ad52adc9addeda704</span>
" `0 \+ v5 O8 e    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)">9 w- Y& K! k4 e9 D7 o& ?' e. r! }
    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>
/ B3 w0 c% u$ K' |    Port:           <span style="color: rgba(128, 0, 128, 1)">5000</span>/<span style="color: rgba(0, 0, 0, 1)">TCP7 N, i' N" t  h0 l+ {8 S, T) W/ U
    Host Port:      </span><span style="color: rgba(128, 0, 128, 1)">0</span>/<span style="color: rgba(0, 0, 0, 1)">TCP
  V. L+ K: G8 T' c1 u+ J2 \8 P    State:          Running
4 H/ g: z; @: e( b      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)">" H4 V* s1 d5 C) b; j
    Ready:          True
2 ?: s( i+ C& s0 I$ p" [, E% M( V& N    Restart Count:  </span><span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">
) W( r5 i6 B% m, E4 n( v7 F1 T0 I/ e    Environment:    </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)"># w( |" \6 O. P8 K
    Mounts:
( X: b  t/ K2 D; s3 u! R1 Q      </span>/tmp from webapp-<span style="color: rgba(0, 0, 0, 1)">logs (rw)5 f; R  ?% a, N1 w" }3 F; n2 z/ Z
      </span>/var/run/secrets/kubernetes.io/serviceaccount from default-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h (ro)  K7 a7 J4 W9 ?& |0 b) `% f( w
  busybox:
. {( S/ E' F% w3 _" w* [) Q* W! ?7 `    Container ID:  docker:</span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">6a6a35a628a782fc643af3dd49986bbc77c23de1ae4726bc521c77f61abbbf5d</span>
: `) J. v2 ?' O% n) m% l6 a2 p/ h( C<span style="color: rgba(0, 0, 0, 1)">    Image:         busybox
: T' p6 g" s* X+ f# j    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>
) w1 F) a; J. o2 w    Port:          &lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">
% p4 k8 \4 ^" M5 l/ M4 c* z' A    Host Port:     </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">
: J1 R: u5 t; f- ]2 n* X    Command:
* p2 }( o  L1 b" N+ |      </span><span style="color: rgba(0, 0, 255, 1)">sh</span>
2 H8 n& `8 I' F* \8 c9 b$ z- N" M0 ~      -<span style="color: rgba(0, 0, 0, 1)">c. G% d" ?& F7 L
      </span><span style="color: rgba(0, 0, 255, 1)">tail</span> -f /logs/<span style="color: rgba(0, 0, 0, 1)">log.out
; b/ C- H5 S6 J+ E3 `9 ^: M0 k! P    State:          Running# `; F: w* t5 \* j0 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)">
& }4 j3 O9 ]- a/ Z% c    Ready:          True
8 ]& C! `4 \3 U# l- k    Restart Count:  </span><span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">9 P% n; l* m% J. ?! T
    Environment:    </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">! @( Z: e% l0 V8 A
    Mounts:
( e; n/ B# O4 G! r+ @( ~      </span>/logs from webapp-<span style="color: rgba(0, 0, 0, 1)">logs (rw)
+ i! h/ `% Q' i      </span>/var/run/secrets/kubernetes.io/serviceaccount from default-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h (ro)
  F) a: ?, {' S5 A: \! jConditions:
0 D1 U' {3 |# N+ v+ l& j; M5 g  Type              Status5 E1 G3 r' K2 F# M
  Initialized       True9 U. B( I2 J) @
  Ready             True
7 S2 ?: V# D7 W5 d  ContainersReady   True& x- o5 Y% [0 y% R
  PodScheduled      True* l/ F6 s( v/ k4 f" m1 ?9 p
Volumes:7 V% b; ?; l! t4 A  X  b% Z
  webapp</span>-<span style="color: rgba(0, 0, 0, 1)">logs:
$ S5 H  P( @3 w9 l    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 a. R, W+ n! l, J3 d- k8 ]<span style="color: rgba(0, 0, 0, 1)">    Medium:
( d, v6 p6 ~6 e1 P) Q; g    SizeLimit:  </span>&lt;unset&gt;<span style="color: rgba(0, 0, 0, 1)">
" _. q+ Y' g0 r0 _% c6 d9 ~  default</span>-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h:4 x; g4 Z7 L" Q9 l! D
    Type:        Secret (a volume populated by a Secret)) o: m" V6 k. o, A
    SecretName:  default</span>-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h
4 l% ^2 I5 M$ e* f1 _1 \    Optional:    </span><span style="color: rgba(0, 0, 255, 1)">false</span><span style="color: rgba(0, 0, 0, 1)">
% [& O4 x1 E9 R& K' tQoS Class:       BestEffort
+ ~7 o& ]5 p9 x& L1 e% fNode</span>-Selectors:  &lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">& G! h* X& S; @
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
+ f. d2 n/ r) v2 v1 D  D; _: L8 l; a                 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
4 o8 O: L% G1 @. SEvents:
7 u+ A' r& R! W  Type    Reason     Age    From               Message
9 Y7 L2 L/ J$ ~& I) D- A  </span>----    ------     ----   ----               -------<span style="color: rgba(0, 0, 0, 1)">
( G5 q7 e/ y6 I+ A% _+ B0 g  Normal  Scheduled  2m23s  default</span>-scheduler  Successfully assigned default/<span style="color: rgba(0, 0, 0, 1)">webapp to ayato
# ~7 a& [2 Q0 {' G. W  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 machine0 I+ o/ \# X. F2 H8 S0 V2 V
  Normal  Created    2m21s  kubelet            Created container webapp) I- i1 j' }3 z( v9 i. f* V
  Normal  Started    2m21s  kubelet            Started container webapp6 A0 E9 X2 w/ a$ F& s  I  W; a; q
  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)">! z9 f$ |4 L. A. _1 H
  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)">.633078305s4 ~. C. F) X, {( Y
  Normal  Created    15s    kubelet            Created container busybox
2 t: D0 Q1 w! p& Z6 t; B* Z) K  Normal  Started    14s    kubelet            Started container busybox</span></pre>, d. b4 ?# ]) G' p
</div>/ S$ F9 w; p; h, v& J
<p>真的是飞一般的感觉!!!</p>
+ O: c; d5 E: q& I2 r) O. ^; J<p>&nbsp;</p>; b5 Z% l9 Q9 ]
<p>三、Context和Namespace切换</p>
6 N( K) J: z+ u- J" g<p>我们在公司的容器平台上使用kubectl时,经常需要切换context和namespace,导致命令非常繁琐,那有没有简便的方式呢?—— kubectx</p>
- K7 M2 I- C* p$ ]<p>kubectx安装</p>% n- Y# Z3 d$ p
<div class="cnblogs_code">6 a9 h  h' p: F9 R7 A% K
<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>6 k' ~& Q2 I$ X
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)">...! }) |! `( X4 S- @" s; i. z
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)">., f: W/ R7 d! a
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)">.
) ]' s" w* U4 f' z4 |% Xremote: Compressing objects: </span><span style="color: rgba(128, 0, 128, 1)">100</span>% (<span style="color: rgba(128, 0, 128, 1)">115</span>/<span style="color: rgba(128, 0, 128, 1)">115</span>), <span style="color: rgba(0, 0, 255, 1)">done</span><span style="color: rgba(0, 0, 0, 1)">.
1 h7 V% c9 z/ P/ {* ~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)">
* Z1 H2 M/ S4 ~" Y  G% |4 a$ qReceiving 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)">.
* @6 U5 s* i0 t. P3 t. y$ nResolving 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)">.) y) W$ L- f; ]4 `
$ </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
" F, A' h, R( Q* V$ L  k3 {$ </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>* @; C: H) l) T' @
</div>
1 |4 E2 r  C) w2 I" a+ T<p>我们来看一下效果:</p>
& ~, S, {' i: y" ~6 l<div class="cnblogs_code">! n. l1 X4 a, A3 P8 ?! g1 T1 x( M
<pre>$ <span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ctx( x0 I( h* X( }; `+ ?
minikube
; I/ l& \+ n0 S5 T5 r; V$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ctx minikube
0 d$ w1 V" o9 F0 d% n( C1 wSwitched 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)">.
( R) D0 S# ~3 ]' W1 t$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ns
5 o) b5 h2 A( S+ Ydefault# e7 S, e7 C; K6 w& U
kube</span>-node-<span style="color: rgba(0, 0, 0, 1)">lease6 Y+ O  v" w) B$ t# o$ e4 @
kube</span>-<span style="color: rgba(0, 0, 0, 1)">public
+ n: d3 B; h' B: v% ykube</span>-<span style="color: rgba(0, 0, 0, 1)">system
) v3 |8 S" T/ Y1 c, Okubernetes</span>-<span style="color: rgba(0, 0, 0, 1)">dashboard4 K% j5 O5 m* B6 f
$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span> k ns kube-<span style="color: rgba(0, 0, 0, 1)">public' \5 C5 M0 |; U% z5 G1 i  q0 L% Y
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.* u. A2 X+ b: W, T' N: y9 [
Active namespace is </span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">kube-public</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)">.
1 _* H# i3 u  x3 d$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ns default
. y% P, Z$ f* f: K4 o) Q. |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.
) U. N! I( w7 M; V$ y* uActive 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>/ o" Z7 }6 Z0 ]* Q' v
</div>. w& W( q# k; Z- G( h
<p>&nbsp;</p>
4 I% l) k: b# j<p>四、跟踪查看多个Pod的日志</p>" g3 ?' P' A1 H) x. H  p
<p>我们一般使用kubectl logs命令查看Pod日志,但是它不能通过-f参数同时跟踪查看多个Pod日志,这就不方便了,毕竟实际生产环境中每个服务都会有多个Pod,这时我们可以使用stern这个工具,它具备如下能力:</p>
9 w! |1 W) I: X" Q6 k<ul class="list-paddingleft-2">+ n& D5 e4 [+ [8 ?/ D# L' x9 `- v: y
<li># z' Z' U8 b2 c# S4 q* D1 |
<p>允许使用正则表达式来选择需要查看的PodName</p>3 h4 \  y7 a& C
</li>
$ U  E% s( m: R- A# b4 l! O$ z<li>7 ^9 s# s2 l8 d2 [/ ]
<p>为不同 Pod 的日志展示不同的颜色</p>
" i% I  H# H1 R( {, ?! B</li>8 ~  p* e3 T6 S" B( f' [' x
<li>% F5 S. {8 N. ~* z0 s2 A6 {/ [
<p>跟踪日志过程中假如有符合规则的新 Pod 被创建, 那么会自动添加到输出中</p>
* R6 m# v( ]& M6 g1 G: ~8 z</li>
$ U6 v0 [2 @  \# j. z</ul>3 N; t. }& o  H
<p>首先安装stern(下载stern时可能较慢可以多试几次):</p>) C7 I  e/ ]+ Y* I7 j# X
<div class="cnblogs_code">
) @0 j" T8 J  ~5 [' @* l, J$ b<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>+ \6 M9 F+ f  q, a6 t6 u
<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>
: ~6 V& {! [5 g3 o% L' ^  H& U' Q& H<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>* G0 |  w0 V" l9 ]
</div>
* G  a7 s6 W' ~! [2 Y<p>安装完毕后让我一起感受一下stern的魅力吧,我的Pod里面有两个容器:webapp和busybox,如果使用kubectl logs 还得指定具体的容器,而使用stern就没有这样的限制。</p>4 r3 _' N/ R' e9 [# U5 d
<div class="cnblogs_code">8 w' z6 S# `0 A5 K& V
<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)"> .
4 P: l6 D/ d2 _( }2 G7 Q; z</span>+<span style="color: rgba(0, 0, 0, 1)"> webapp › busybox3 z/ N( G" r! k# h
</span>+<span style="color: rgba(0, 0, 0, 1)"> webapp › webapp% p* [* R$ l; A% ~/ K1 s+ 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.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)">]
1 {& M5 O$ |; E" Z8 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)">53.200</span><span style="color: rgba(0, 0, 0, 1)"> [INFO ] [main] [org.apache.catalina.core.StandardService] Starting service [Tomcat]6 a6 ?. W9 L. L5 m! y  c  M
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)">]
- H, y( e% D; T7 {  V) 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)">53.324</span> [INFO ] [main] [org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/<span style="color: rgba(0, 0, 0, 1)">]] Initializing Spring embedded WebApplicationContext
% U: o+ R+ C) W* a5 H6 Nwebapp busybox </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">53.325</span> [INFO ] [main] [org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext] Root WebApplicationContext: initialization completed <span style="color: rgba(0, 0, 255, 1)">in</span> <span style="color: rgba(128, 0, 128, 1)">2952</span><span style="color: rgba(0, 0, 0, 1)"> ms* ~; u7 r, e$ C/ v1 q% |
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)">
) j6 a! U8 V2 c- e# b7 `2 gwebapp busybox </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">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 ]& o% r% d. {2 r8 e' c! p; b6 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)">54.377</span> [INFO ] [main] [org.apache.coyote.http11.Http11NioProtocol] Starting ProtocolHandler [<span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">http-nio-4567</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)">]9 w0 N4 I, f) V3 a& N, H6 V% N* 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)">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)">
# d: L8 l" X  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.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)">)' ?' p' W/ u! _0 J
webapp webapp
8 c* n" v$ U. u" \; e) x) Nwebapp webapp   .   ____          _            __ _ _
1 o  D/ L' p! v, b0 Lwebapp webapp  </span>/\\ / ___<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">_ __ _ _(_)_ __  __ _ \ \ \ \</span>
1 G8 w& y5 A" d* v; o* e0 pwebapp 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>+ e  b  S1 ~4 O5 N9 Z( V, Y
webapp webapp  \\/  ___)| |_)| | | | | || (_| |<span style="color: rgba(0, 0, 0, 1)">  ) ) ) )
7 ~0 O3 d  ~- b$ l- Kwebapp webapp   </span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">  |____| .__|_| |_|_| |_\__, | / / / /</span>. f$ b8 f1 q5 y
webapp webapp  =========|_|==============|___/=/_/_/_/<span style="color: rgba(0, 0, 0, 1)">
: g0 g9 x5 W7 s; _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)">)
' ?' W4 b/ |9 a2 jwebapp webapp
5 H3 Z, t! p( }) uwebapp 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)
1 b* n9 G: j  J+ U5 F8 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)">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% L, h1 W8 F1 C7 g( ~" [* F
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)" j9 J4 u& b, `% U) 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)">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)">]
5 F/ L+ H5 [6 _  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.200</span><span style="color: rgba(0, 0, 0, 1)"> [INFO ] [main] [org.apache.catalina.core.StandardService] Starting service [Tomcat]: p7 V( j& v: ~3 k& `8 J& G7 o5 c
webapp webapp </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">53.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)">]% B( w$ r& [- [5 Y: ?* Y9 O- {) H
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' p7 G  ]6 W  \! `* F1 e5 v) c
webapp webapp </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">53.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
# E2 E+ W" T# b: S8 i  i  B9 Mwebapp webapp </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">53.801</span> [INFO ] [main] [org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor] Initializing ExecutorService <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">applicationTaskExecutor</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">
9 `/ Y" R9 v& b: |$ Jwebapp 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)
" x5 q+ E# I6 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.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)">]
% R$ G1 g, z* N2 E& R0 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)">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)">
1 Y, T2 {0 m  d- t( t( d* ]% `( Uwebapp 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>& ?: E$ a" M; k
</div>7 B3 x( l+ J1 L0 E$ q% d
<p>&nbsp;</p># G3 C" u, H5 p0 g
回复

使用道具 举报

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

本版积分规则

手机版|飞雪团队

GMT+8, 2026-6-24 01:56 , Processed in 0.069479 second(s), 21 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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