飞雪团队

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

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

[复制链接]

7559

主题

7647

帖子

2万

积分

管理员

Rank: 9Rank: 9Rank: 9

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

5 l0 c, o, s2 X<p>kubectl作为我们主要的操作K8S的工具,其具备非常丰富的功能,但是如果不经过打磨,使用起来还是存在诸多不便,今天我们来看看如何将我们的kubectl打磨的更加易用。</p>1 ~' \$ m3 f* I7 Y. K% f
<p>&nbsp;</p>
4 |2 R) d# Q2 b) r, t) M<p>一、命令自动补全</p>
$ A" _8 ?  e6 f, c9 @# a/ X# F<p>kubectl中提供非常多的命令,如果每一次都要手动一个字符一个字符的敲未免太累了,那么如何配置自动补全呢?这里以ubuntu系统为例:</p>
8 b4 |8 @. H! s* e5 O  Q/ z<p>1、安装auto-completion工具</p>
  k4 u' E$ j; B$ L" M" I6 t% J<div class="cnblogs_code">
% h8 `: v  Y2 c) X! _<pre>$ <span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> apt update0 V8 e/ ~* B: W2 Y
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>) X  |2 E2 t2 h$ c9 P6 |
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>
4 o4 r$ f* I- \3 n3 F$ THit:<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>, z% e' w5 a: k+ `4 e$ I& J
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># b; @5 ?1 q# u; o7 V2 n( T
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>2 I5 e# T! ]' r" t/ ?
<span style="color: rgba(0, 0, 0, 1)">Reading package lists... Done
5 s7 j& z0 Y  D' e+ pBuilding dependency tree/ w, @( v' p8 U' P  d
Reading state information... Done
0 f3 Q5 F( u$ ?6 l' Q1 @</span><span style="color: rgba(128, 0, 128, 1)">144</span> packages can be upgraded. Run <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">apt list --upgradable</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)"> to see them.8 k/ P) }: T1 q' S; H
$ </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
, k0 R) D: _  p+ kReading package lists... Done
1 w0 ~6 b7 l3 D7 A, Y! b$ ABuilding dependency tree
8 }4 g# i1 e% X/ F# O) SReading state information... Done; v5 A" J1 P  J, }' }
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).. K+ t$ \7 J# M4 R
</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>/ u0 `0 T! [% E  m, N. ^  Q
</div>
; e2 i$ k( h& F* l9 o<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>
2 N1 h! f7 n! b9 x<p>2、<span class="js_darkmode__1" data-darkmode-color-16446330660319="rgb(163, 163, 163)" data-darkmode-original-color-16446330660319="#fff|rgb(0, 0, 0)" data-style="color: rgb(0, 0, 0);">配置自动补全<br></span></p>4 M( H$ X$ F* F; I6 U# y
<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>& W9 a" n5 a) l4 R9 l
<div class="cnblogs_code">( {2 ~6 c) t+ t
<pre>source &lt;<span style="color: rgba(0, 0, 0, 1)">(kubectl completion bash)
7 P& B& q5 j9 i  P! \$ a$ T</span><span style="color: rgba(0, 0, 255, 1)">echo</span> <span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">source &lt;(kubectl completion bash)</span><span style="color: rgba(128, 0, 0, 1)">"</span> &gt;&gt; ~/.bashrc</pre>. f& Z' U/ p; a7 e" s; F
</div>
3 h4 i% N5 t/ q, s" d<p><strong>Zsh</strong>:</p>
; ~& z# I- `" X- h4 y- F6 U8 i<div class="cnblogs_code">
- a! A) i/ B9 H3 E. }; I<pre>source &lt;<span style="color: rgba(0, 0, 0, 1)">(kubectl completion zsh)/ _; Q& r" n- C+ p! ]
</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>1 d' _. {8 ?2 [
</div>
" s  w1 n: T, r( F5 t. o0 G<p>配置后就可以通过Tab键自动补全命令啦!</p>' |! d. X: i! w) y$ x
<p>&nbsp;</p>
( k6 d5 s: J' v/ Z+ F# N6 x1 s<p>二、配置kubectl别名</p>
! C0 X3 z  y* z- {. M<p>我们可以通过设置别名简化kubectl命令,编辑.bashrc文件,添加如下内容:</p>
, S# V: R: A2 d* O' Q- M<div class="cnblogs_code">
, b& y$ p! C9 f, e- a<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 j8 j! Y/ l1 Z# ]; r' {# ^
alias k</span>=<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">kubectl</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">
( z- u( ~& k7 G8 w5 m/ halias 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 }5 f4 C/ P3 t- l" j6 K; w% \alias kex</span>=<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">kubectl exec -i -t</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">
- n9 \# V0 l$ q! Palias 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)">
8 [0 Z) d7 d/ Q4 ?) E& W9 Ralias 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)"># k: ?1 m* I4 V1 a' u
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>
" D' r% j9 W' L& L! I( ?4 F</div>
; K; t$ ^+ z1 g3 |" Z<p><span class="js_darkmode__4" data-darkmode-color-16446330660319="rgb(0, 104, 255)" data-darkmode-original-color-16446330660319="#fff|rgb(0, 82, 255)" data-style="color: rgb(0, 82, 255);"><strong data-darkmode-color-16446330660319="rgb(0, 104, 255)" data-darkmode-original-color-16446330660319="#fff|rgb(0, 82, 255)">PS:alias sudo是为了解决sudo下别名不可用问题</strong><br></span></p>
- d$ D) S2 k- ~% E5 ~) d6 z<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>( ^, V( P% e9 \2 `7 }5 ~) X! |" i
<div class="cnblogs_code">" R% |! |8 }8 R4 s8 Y
<pre>$ <span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> ka webapp_pod.yaml
7 J. y/ J* X: Epod</span>/<span style="color: rgba(0, 0, 0, 1)">webapp created* r" a+ z8 p% U& u+ z
$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> kg pods
' I1 h+ j+ K; J8 VNAME     READY   STATUS              RESTARTS   AGE, y: i3 t3 T; t6 ~* A
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
+ J! |4 C+ S; K* m1 U$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> kd pod webapp
9 Z0 s! r; ?$ I9 KName:         webapp- x, z0 B- z9 x" R$ q* O
Namespace:    default; j, ^. K: l7 ^% q5 n4 S0 @9 t% }2 F
Priority:     </span><span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">$ Q1 T4 f2 B3 P8 j3 L
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)">% ^% \. N5 ^" ~1 o' B% R" o
Start Time:   Wed, </span><span style="color: rgba(128, 0, 128, 1)">09</span> Feb <span style="color: rgba(128, 0, 128, 1)">2022</span> <span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">44</span> +<span style="color: rgba(128, 0, 128, 1)">0000</span><span style="color: rgba(0, 0, 0, 1)">8 X1 T  {, b. D4 G& O
Labels:       app</span>=<span style="color: rgba(0, 0, 0, 1)">webapp
* a( ?& N5 V6 K& G4 Z+ MAnnotations:  </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">
7 A* {# z/ k& i' E( A& pStatus:       Running2 _7 d8 f* @  J- P8 S
IP:           </span><span style="color: rgba(128, 0, 128, 1)">172.17</span>.<span style="color: rgba(128, 0, 128, 1)">0.6</span><span style="color: rgba(0, 0, 0, 1)">. n" {0 r6 l  t/ i7 {7 E
IPs:$ {7 B1 F2 x% W5 ^
  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)">
3 d3 T$ `9 C1 U* WContainers:/ W$ I3 h4 k' I7 ^7 F& i2 B
  webapp:0 u3 i% c5 b# ]  X
    Container ID:   docker:</span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">d9ddf9dd47de12b53f2119bf75df6706bee2e7711509638ad52adc9addeda704</span>/ N7 M8 e5 h5 l1 {
    Image:          <span style="color: rgba(128, 0, 128, 1)">172.16</span>.<span style="color: rgba(128, 0, 128, 1)">194.135</span>:<span style="color: rgba(128, 0, 128, 1)">5000</span>/webapp:<span style="color: rgba(128, 0, 128, 1)">1.0</span><span style="color: rgba(0, 0, 0, 1)">0 Q3 E6 V# R. K/ P2 ~2 R" f( D
    Image ID:       docker</span>-pullable:<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">172.16.194.135:5000/webapp@sha256:df3a447a013ada0642dec67bb31976f42f1a0699a68873d0452f514fa24e5c77</span>+ J* a# }2 }' q* B
    Port:           <span style="color: rgba(128, 0, 128, 1)">5000</span>/<span style="color: rgba(0, 0, 0, 1)">TCP9 Q/ t3 F* O% R5 @4 k, J% L$ W. Q
    Host Port:      </span><span style="color: rgba(128, 0, 128, 1)">0</span>/<span style="color: rgba(0, 0, 0, 1)">TCP
0 v7 [( V; V9 j    State:          Running! Y# h1 j* d3 _8 \& N; t/ n
      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)">4 V* R  b2 g6 x) e* j5 ^
    Ready:          True
# J; t, ~7 a" G: S" |    Restart Count:  </span><span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">
& N* @/ C  D# ?$ w9 O    Environment:    </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">
, _: I7 M1 Q# ^' D; ]" [    Mounts:
+ \& Y% h( e/ g+ }! U( w, e      </span>/tmp from webapp-<span style="color: rgba(0, 0, 0, 1)">logs (rw)
, |; E* t' D6 I# |" A8 A      </span>/var/run/secrets/kubernetes.io/serviceaccount from default-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h (ro)
. B! R: J+ K4 K* R/ M  busybox:
* w# U* U! Q: v" |& p: [8 ?    Container ID:  docker:</span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">6a6a35a628a782fc643af3dd49986bbc77c23de1ae4726bc521c77f61abbbf5d</span>0 Q: o/ h, T4 I* x" m9 s/ K
<span style="color: rgba(0, 0, 0, 1)">    Image:         busybox4 g0 H7 I$ h8 z, T' @9 r7 f8 P
    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>
& i' l( P: ]/ a4 E* v    Port:          &lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">4 B0 t8 ~( q1 S; A* Z: X
    Host Port:     </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">
2 [5 Z- ^( V2 c  @8 p5 @! P    Command:0 q3 B$ z: _% `$ x9 p
      </span><span style="color: rgba(0, 0, 255, 1)">sh</span>
5 }3 P7 O6 H* n1 Y2 A6 w, a      -<span style="color: rgba(0, 0, 0, 1)">c- s3 o  Y  l9 Q  o9 _5 n. F
      </span><span style="color: rgba(0, 0, 255, 1)">tail</span> -f /logs/<span style="color: rgba(0, 0, 0, 1)">log.out
5 G4 I2 ]& R4 n$ b  |    State:          Running
6 D: j" T& v& O9 h; 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)">
' k/ k, L! u) F0 U' D& H    Ready:          True
/ o. f# Y: U% G/ ]    Restart Count:  </span><span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">' N7 ]% q; ]" u; |
    Environment:    </span>&lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">! Z5 r1 Y$ j5 P  f0 l
    Mounts:
  M/ p  ~* P  s      </span>/logs from webapp-<span style="color: rgba(0, 0, 0, 1)">logs (rw)
5 v' p+ r% U- k# G. k      </span>/var/run/secrets/kubernetes.io/serviceaccount from default-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h (ro)- P8 i0 k7 e( c6 c6 a! o
Conditions:
, k! K2 L& L% R* j  Type              Status
4 v9 w0 I( d; E6 J  Initialized       True: r1 S% b3 o0 R7 Z; i' d
  Ready             True* ~* ]( T% ^2 j
  ContainersReady   True
* I7 p- ?. v  I& O  PodScheduled      True. W1 }" n7 E& V: E
Volumes:0 M8 d  x$ Q0 j& q: P. O" |! r
  webapp</span>-<span style="color: rgba(0, 0, 0, 1)">logs:
6 {+ `# T/ Z# n    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>
0 P/ a- a# I" f. i$ Z# |0 o& ~8 ^" O<span style="color: rgba(0, 0, 0, 1)">    Medium:
4 d' j/ |  d0 Y8 ?    SizeLimit:  </span>&lt;unset&gt;<span style="color: rgba(0, 0, 0, 1)">" j* K& _' t" G1 u2 e2 i
  default</span>-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h:
. O, D; Q2 a* l/ r$ L8 B    Type:        Secret (a volume populated by a Secret)/ `$ ~$ B. {8 h  J5 s( ~; h8 ]3 O
    SecretName:  default</span>-token-<span style="color: rgba(0, 0, 0, 1)">pcr2h
/ _4 x1 T+ A- B( v' O    Optional:    </span><span style="color: rgba(0, 0, 255, 1)">false</span><span style="color: rgba(0, 0, 0, 1)">
+ {/ s3 {7 V1 F2 kQoS Class:       BestEffort- u$ G- N  d, c
Node</span>-Selectors:  &lt;none&gt;<span style="color: rgba(0, 0, 0, 1)">' a5 A; q% Q$ e" F! w) m
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# X9 `5 b9 c* @8 y4 P
                 node.kubernetes.io</span>/unreachable:NoExecute op=Exists <span style="color: rgba(0, 0, 255, 1)">for</span><span style="color: rgba(0, 0, 0, 1)"> 300s
7 b# f8 P* h; d* n0 {+ q& kEvents:8 c+ t$ Y: T# o0 S& j' Z6 x
  Type    Reason     Age    From               Message' E, p' V$ ^) l; _
  </span>----    ------     ----   ----               -------<span style="color: rgba(0, 0, 0, 1)">
+ g8 \/ n" X& w9 V: _  Normal  Scheduled  2m23s  default</span>-scheduler  Successfully assigned default/<span style="color: rgba(0, 0, 0, 1)">webapp to ayato3 ~& a: {* o: K  V: j5 }
  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/ u7 l, J" Y! y! Q4 V- Q8 ?
  Normal  Created    2m21s  kubelet            Created container webapp
" A6 W/ T2 }' e  ]' [  Normal  Started    2m21s  kubelet            Started container webapp
1 p0 Y; d4 W) m  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)">0 ~4 E; g" |5 q, w
  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
& u# I2 |9 |, g3 g  Normal  Created    15s    kubelet            Created container busybox
, T2 }: x5 A8 J  Normal  Started    14s    kubelet            Started container busybox</span></pre>& }3 e; C$ T* ]! B( W% W- \
</div>2 R3 ^% S, E2 T% @: K; o
<p>真的是飞一般的感觉!!!</p>
( }0 b6 G0 R. F<p>&nbsp;</p>$ h5 H3 J* _8 P0 c) Y4 X
<p>三、Context和Namespace切换</p>
1 B& ?: o3 R# }6 Y+ Y; z<p>我们在公司的容器平台上使用kubectl时,经常需要切换context和namespace,导致命令非常繁琐,那有没有简便的方式呢?—— kubectx</p>
( l5 H: I1 e5 e# C3 z<p>kubectx安装</p>8 B) b4 G  P5 u) M+ E
<div class="cnblogs_code">
9 {& O+ s, e. f8 R4 j: S: J<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>5 ~3 b- K% {$ y; s2 I+ u- v
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)">...
+ D* n: M# H, U- I7 z9 R/ Nremote: 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)">.
( A6 r& Y& z7 P6 W. p3 ]# ~& ~! premote: 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 t/ Y: }6 p1 s, [
remote: Compressing objects: </span><span style="color: rgba(128, 0, 128, 1)">100</span>% (<span style="color: rgba(128, 0, 128, 1)">115</span>/<span style="color: rgba(128, 0, 128, 1)">115</span>), <span style="color: rgba(0, 0, 255, 1)">done</span><span style="color: rgba(0, 0, 0, 1)">.7 E& f( B6 W. \, j. F6 h
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)">
! K$ \3 n7 d8 q. z* B5 NReceiving 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)">.+ N2 M. L5 X  p
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)">.1 K; W' l2 t+ A0 G
$ </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)">ns9 d! W, D% `+ y( N/ b' ?
$ </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>7 j) [7 W. w' H, C5 R; ?
</div>
& f  C. g1 v9 x- q5 ?" N<p>我们来看一下效果:</p>- ~3 P9 U1 a; R
<div class="cnblogs_code">
4 S, D# A& ?) Z& V<pre>$ <span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ctx
/ j; q* M' z. p4 |  x( U# @minikube
* o5 e7 ]( r( C& |$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ctx minikube7 b; I2 \  A, S* g( b3 r/ I
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)">.
- a/ X5 O, G/ C# O$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ns
. p% ~" B' p! @. p: h! i+ `default
6 d- G4 X# A- \' W6 S) J5 G0 ^) ?0 w& {kube</span>-node-<span style="color: rgba(0, 0, 0, 1)">lease# }7 J/ v1 L% C4 K3 Q+ F$ F
kube</span>-<span style="color: rgba(0, 0, 0, 1)">public
2 [% p, S& T" ~4 p. a0 R$ H6 Ckube</span>-<span style="color: rgba(0, 0, 0, 1)">system
* h' P$ M9 v/ p( n5 v: okubernetes</span>-<span style="color: rgba(0, 0, 0, 1)">dashboard
" E% h: P2 z, B$ C+ n) P7 M8 j) P$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span> k ns kube-<span style="color: rgba(0, 0, 0, 1)">public
. x3 Y/ |; j3 h' l* m/ SContext </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.
- F8 Z" K: o/ [* R# b0 `6 ~/ Z+ nActive 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)">.
: E* F# U& D  Q9 j$ </span><span style="color: rgba(0, 0, 255, 1)">sudo</span><span style="color: rgba(0, 0, 0, 1)"> k ns default0 O* b+ a4 t2 n) g
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.8 A$ K; [& Q% w  ~
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>
) L5 ?6 D1 |0 ]. }</div>5 }  i! i0 q0 e: Q% G4 Y5 b6 K3 z. [
<p>&nbsp;</p>9 ]# \2 z/ n+ M1 O" c9 l
<p>四、跟踪查看多个Pod的日志</p>4 z" c- i$ J  b
<p>我们一般使用kubectl logs命令查看Pod日志,但是它不能通过-f参数同时跟踪查看多个Pod日志,这就不方便了,毕竟实际生产环境中每个服务都会有多个Pod,这时我们可以使用stern这个工具,它具备如下能力:</p>
* k! {+ T( L0 \8 l# r2 w<ul class="list-paddingleft-2">
5 X; r0 v3 v; ?1 C( a<li>
1 \$ x# N, e% |3 m' Y- ?+ X<p>允许使用正则表达式来选择需要查看的PodName</p>
0 b, A! R# Z5 X' q/ F</li>  N! t" d5 q$ ]: `8 w6 C
<li>
1 v, z2 z8 _0 w% a) g4 a<p>为不同 Pod 的日志展示不同的颜色</p>
9 B  Q) [; B' l$ U4 Y' v2 M6 l</li>. _" N. Q7 p: E) [8 B* z2 X" `5 {
<li>
2 b$ c4 R4 u' z! A2 }2 _<p>跟踪日志过程中假如有符合规则的新 Pod 被创建, 那么会自动添加到输出中</p>
/ j  R( j2 o" Y, S  @6 w" {' X- X</li>( g7 z. S3 ?: Z! g+ n0 d, F
</ul>
+ d7 A7 i  z5 h1 m6 R  X! D<p>首先安装stern(下载stern时可能较慢可以多试几次):</p>0 X6 p. U- u8 g
<div class="cnblogs_code">5 N3 O: B$ W/ v( _& {" O
<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>
4 }, \, W' ^) z" y2 a<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>
+ s5 C: {. ~1 h: H! s3 E: {<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>* }; e5 l  ^, l- P  K* g
</div>
: |; [' ]3 P4 B  C  d. j' l$ M/ @<p>安装完毕后让我一起感受一下stern的魅力吧,我的Pod里面有两个容器:webapp和busybox,如果使用kubectl logs 还得指定具体的容器,而使用stern就没有这样的限制。</p>
3 z% u* s/ O4 M' M+ s<div class="cnblogs_code">% {( r& n: ?% O, Y# y& L
<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 A4 P, G0 E& V( d4 v/ G
</span>+<span style="color: rgba(0, 0, 0, 1)"> webapp › busybox& k: ?1 Q3 Y+ B) v) i& {' Z
</span>+<span style="color: rgba(0, 0, 0, 1)"> webapp › webapp
' s# I) }) B, ~webapp busybox </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">53.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)">]
" l. M; O) r2 [* Q4 Twebapp 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]  c  s( Q7 \4 h
webapp busybox </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">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)">]' Z* k( g, m  K! O% G' |; y
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
3 t" u; {  N! h, h4 i# M: jwebapp busybox </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">53.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, U% S5 J4 ]( }( 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.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)">* y$ K' L/ p4 @
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)9 Z" }- l3 u: E) J! j" A
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)">]1 ?: B* 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)">. u" {- ?) G; ?5 v; T+ v$ T
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)">): ^% Y- u  l* Y, ^9 Q! c
webapp webapp7 \3 r* Q! M# h+ J) ^- _
webapp webapp   .   ____          _            __ _ _  B! u6 A. O7 [. w1 L
webapp webapp  </span>/\\ / ___<span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">_ __ _ _(_)_ __  __ _ \ \ \ \</span>
7 B0 q- z" r+ y4 d3 @+ l# }" owebapp 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>" k5 m5 O( I, d0 f7 n2 K8 S% Q- M
webapp webapp  \\/  ___)| |_)| | | | | || (_| |<span style="color: rgba(0, 0, 0, 1)">  ) ) ) )$ n/ z  z& y2 ^* i, b# M
webapp webapp   </span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">  |____| .__|_| |_|_| |_\__, | / / / /</span>
, r0 J! A+ B# m$ Uwebapp webapp  =========|_|==============|___/=/_/_/_/<span style="color: rgba(0, 0, 0, 1)">8 z& E) T4 u9 E- d8 k
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 u0 v/ D% `/ D. ^+ Qwebapp webapp8 t/ M6 F! u$ R8 m* Q* C1 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)">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)
. i" D4 K: s+ S0 ~' v9 o. u: 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)">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
; i* q0 ~" e# C; _+ m- 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)
+ O  K$ Y* z  k# B' kwebapp webapp </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">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)">]  L3 X) V! h0 D7 y+ x% 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.200</span><span style="color: rgba(0, 0, 0, 1)"> [INFO ] [main] [org.apache.catalina.core.StandardService] Starting service [Tomcat]- p0 d$ c# 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)">]
( @& o) |2 ]; }; nwebapp 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; ?. p5 P# g0 m* {# w( f3 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.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
. V9 N8 B1 j- 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)">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)">
$ t2 o* {" v0 a7 |) h* b9 e# Swebapp 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)
; _# G+ q( D! I& n8 ]- hwebapp webapp </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">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)">]
; t) {1 C& q. }* v4 iwebapp webapp </span><span style="color: rgba(128, 0, 128, 1)">14</span>:<span style="color: rgba(128, 0, 128, 1)">04</span>:<span style="color: rgba(128, 0, 128, 1)">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)">' V% \3 r8 k4 m3 I6 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)">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>
/ Y! }! p/ V5 h5 d, u% N6 e* u</div>
6 l$ u) x6 w" n' p: i& \<p>&nbsp;</p>
8 }# g0 Q, ]; O/ G) q  k4 a' n6 I
回复

使用道具 举报

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

本版积分规则

手机版|飞雪团队

GMT+8, 2025-9-16 00:24 , Processed in 0.081347 second(s), 22 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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