kubernetes核心概念 Service

kubernetes核心概念 Service

  • kubernetes核心概念 Service
  • 一、 service作用
  • 二、kube-proxy三种代理模式
    • 2.1 UserSpace模式
    • 2.2 iptables模式
    • 2.3 ipvs模式
    • 2.4 iptables与ipvs对比
  • 三、 service类型
    • 3.1 service类型
    • 3.2 Service参数
  • 四、 Service创建
    • 4.1 ClusterIP类型
      • 4.1.1 普通ClusterIP Service创建
        • 4.1.1.1 命令行创建Service
        • 4.1.1.2 通过资源清单文件创建Service
        • 4.1.1.3 访问
        • 4.1.1.4 两个pod里做成不同的主页方便测试负载均衡
        • 4.1.1.5 测试
      • 4.1.2 Headless Service
        • 4.1.2.1 编写用于创建Deployment控制器类型的资源清单文件
        • 4.1.2.2 通过资源清单文件创建headless Service
        • 4.1.2.3 应用资源清单文件创建headless Service
        • 4.1.2.4 查看已创建的headless Service
        • 4.1.2.5 DNS
          • 4.1.2.5.1 查看kube-dns服务的IP
          • 4.1.2.5.2 在集群主机通过DNS服务地址查找无头服务的dns解析
          • 4.1.2.5.3 验证pod的IP
          • 4.1.2.5.4 在集群中创建一个pod验证
    • 4.2 NodePort类型
    • 4.3 LoadBalancer
      • 4.3.1 集群外访问过程
        • 用户
        • 域名
        • 云服务提供商提供LB服务
        • NodeIP:Port(service IP)
        • Pod IP:端口
      • 4.3.2 自建Kubernetes的LoadBalancer类型服务方案-MetalLB
        • 4.3.2.1 参考资料
        • 4.3.2.2 应用资源清单文件
        • 4.3.2.3 准备metallb配置文件
        • 4.3.2.4发布Service类型为LoadBalancer的Deployment控制器类型应用
        • 4.3.2.5 验证
        • 4.3.2.6 访问
    • 4.4 ExternalName
      • 4.4.1 ExternalName作用
      • 4.4.2 将公网域名引入
      • 4.4.3 不同命名空间访问
  • 五、sessionAffinity
  • 六、修改为ipvs调度方式(拓展)
    • 6.1 修改为IPVS调度方式前升级内核
    • 6.2 修改kube-proxy的配置文件
    • 6.3 查看kube-system的namespace中kube-proxy有关的pod
    • 6.4 验证kube-proxy-xxx的pod中的信息
    • 6.5 重新启动kube-proxy

kubernetes核心概念 Service

一、 service作用

使用 kubernetes 集群运行工作负载时,由于Pod经常处于用后即焚状态,Pod经常被重新生成,因此Pod对应的IP地址也会经常变化,导致无法直接访问Pod提供的服务,Kubernetes中使用了Service来解决这一问题,即在Pod前面使用Service对Pod进行代理,无论Pod怎样变化 ,只要有Label,就可以让Service能够联系上Pod,把PodIP地址添加到Service对应的端点列表(Endpoints)实现对Pod IP跟踪,进而实现通过Service访问Pod。

  • 通过service为pod客户端提供访问pod的方法,即客户端访问pod入口
  • 通过标签动态感知pod IP地址变化等
  • 防止pod失联
  • 定义访问pod访问策略
  • 通过label-selector相关联
  • 通过Service实现Pod的负载均衡(TCP/UDP 4层)
  • 底层实现由kube-proxy通过userspace、iptables、ipvs三种代理模式

二、kube-proxy三种代理模式

  • kubernetes集群中有三层网络,一类是真实存在的,例如Node Network、Pod Network,提供真实IP地址;一类是虚拟的,例如Cluster Network或Service Network,提供虚拟IP地址,不会出现在接口上,仅会出现在Service当中

  • kube-proxy始终watch(监控)kube-apiserver上关于Service相关的资源变动状态,一旦获取相关信息kube-proxy都要把相关信息转化为当前节点之上的,能够实现Service资源调度到特定Pod之上的规则,进而实现访问Service就能够获取Pod所提供的服务

  • kube-proxy三种代理模式:UserSpace模式、iptables模式、ipvs模式

2.1 UserSpace模式

userspace 模式是 kube-proxy 使用的第一代模式,该模式在 kubernetes v1.0 版本开始支持使用。

userspace 模式的实现原理:

kubernetes核心概念 Service_第1张图片

kube-proxy 会为每个 Service 随机监听一个端口(proxy port),并增加一条 iptables 规则。所以通过 ClusterIP:Port 访问 Service 的报文都 redirect 到 proxy port,kube-proxy 从它监听的 proxy port 收到报文以后,走 round robin(默认) 或是 session affinity(会话亲和力,即同一 client IP 都走同一链路给同一 pod 服务),分发给对应的 pod。

由于 userspace 模式会造成所有报文都走一遍用户态(也就是 Service 请求会先从用户空间进入内核 iptables,然后再回到用户空间,由 kube-proxy 完成后端 Endpoints 的选择和代理工作),需要在内核空间和用户空间转换,流量从用户空间进出内核会带来性能损耗,所以这种模式效率低、性能不高,不推荐使用。

kubernetes核心概念 Service_第2张图片

2.2 iptables模式

iptables 模式是 kube-proxy 使用的第二代模式,该模式在 kubernetes v1.1 版本开始支持,从 v1.2 版本开始成为 kube-proxy 的默认模式。

iptables 模式的负载均衡模式是通过底层 netfilter/iptables 规则来实现的,通过 Informer 机制 Watch 接口实时跟踪 Service 和 Endpoint 的变更事件,并触发对 iptables 规则的同步更新。

iptables 模式的实现原理图示如下:

kubernetes核心概念 Service_第3张图片

通过图示我们可以发现在 iptables 模式下,kube-proxy 只是作为 controller,而不是 server,真正服务的是内核的 netfilter,体现在用户态的是 iptables。所以整体的效率会比 userspace 模式高。

kubernetes核心概念 Service_第4张图片

2.3 ipvs模式

ipvs 模式被 kube-proxy 采纳为第三代模式,模式在 kubernetes v1.8 版本开始引入,在 v1.9 版本中处于 beta 阶段,在 v1.11 版本中正式开始使用。

ipvs(IP Virtual Server) 实现了传输层负载均衡,也就是 4 层交换,作为 Linux 内核的一部分。ipvs运行在主机上,在真实服务器前充当负载均衡器。ipvs 可以将基于 TCP 和 UDP 的服务请求转发到真实服务器上,并使真实服务器上的服务在单个 IP 地址上显示为虚拟服务。

ipvs 模式的实现原理图示如下:

kubernetes核心概念 Service_第5张图片

kubernetes核心概念 Service_第6张图片

ipvs 和 iptables 都是基于 netfilter 的,那么 ipvs 模式有哪些更好的性能呢?

  • ipvs 为大型集群提供了更好的可拓展性和性能
  • ipvs 支持比 iptables 更复杂的负载均衡算法(包括:最小负载、最少连接、加权等)
  • ipvs 支持服务器健康检查和连接重试等功能
  • 可以动态修改 ipset 的集合,即使 iptables 的规则正在使用这个集合

ipvs 依赖于 iptables。ipvs 会使用 iptables 进行包过滤、airpin-masquerade tricks(地址伪装)、SNAT 等功能,但是使用的是 iptables 的扩展 ipset,并不是直接调用 iptables 来生成规则链。通过 ipset 来存储需要 DROP 或 masquerade 的流量的源或目标地址,用于确保 iptables 规则的数量是恒定的,这样我们就不需要关心有多少 Service 或是 Pod 了。

使用 ipset 相较于 iptables 有什么优点呢?iptables 是线性的数据结构,而 ipset 引入了带索引的数据结构,当规则很多的时候,ipset 依然可以很高效的查找和匹配。我们可以将 ipset 简单理解为一个 IP(段) 的集合,这个集合的内容可以是 IP 地址、IP 网段、端口等,iptables 可以直接添加规则对这个“可变的集合进行操作”,这样就可以大大减少 iptables 规则的数量,从而减少性能损耗。

举一个例子,如果我们要禁止成千上万个 IP 访问我们的服务器,如果使用 iptables 就需要一条一条的添加规则,这样会在 iptables 中生成大量的规则;如果用 ipset 就只需要将相关的 IP 地址(网段)加入到 ipset 集合中,然后只需要设置少量的 iptables 规则就可以实现这个目标。

下面的表格是 ipvs 模式下维护的 ipset 表集合:

设置名称 成员 用法
KUBE-CLUSTER-IP 所有服务 IP + 端口 在 masquerade-all=true 或 clusterCIDR 指定的情况下对 Service Cluster IP 地址进行伪装,解决数据包欺骗问题
KUBE-LOOP-BACK 所有服务 IP + 端口 + IP 解决数据包欺骗问题
KUBE-EXTERNAL-IP 服务外部 IP + 端口 将数据包伪装成 Service 的外部 IP 地址
KUBE-LOAD-BALANCER 负载均衡器入口 IP + 端口 将数据包伪装成 Load Balancer 类型的 Service
KUBE-LOAD-BALANCER-LOCAL 负载均衡器入口 IP + 端口 以及externalTrafficPolicy=local 接受数据包到 Load Balancer externalTrafficPolicy=local
KUBE-LOAD-BALANCER-FW 负载均衡器入口 IP + 端口 以及loadBalancerSourceRanges 使用指定的 loadBalancerSourceRanges 丢弃 Load Balancer 类型 Service 的数据包
KUBE-LOAD-BALANCER-SOURCE-CIDR 负载均衡器入口 IP + 端口 + 源 CIDR 接受 Load Balancer 类型 Service 的数据包,并指定 loadBalancerSourceRanges
KUBE-NODE-PORT-TCP NodePort 类型服务 TCP 端口 将数据包伪装成 NodePort(TCP)
KUBE-NODE-PORT-LOCAL-TCP NodePort 类型服务 TCP 端口,带有externalTrafficPolicy=local 接受数据包到 NodePort 服务,使用 externalTrafficPolicy=local
KUBE-NODE-PORT-UDP NodePort 类型服务 UDP 端口 将数据包伪装成 NodePort(UDP)
KUBE-NODE-PORT-LOCAL-UDP NodePort 类型服务 UDP 端口,使用externalTrafficPolicy=local 接受数据包到 NodePort 服务,使用 externalTrafficPolicy=local

2.4 iptables与ipvs对比

  • iptables

    • 工作在内核空间
    • 优点
      • 灵活,功能强大(可以在数据包不同阶段对包进行操作)
    • 缺点
      • 表中规则过多时,响应变慢,即规则遍历匹配和更新,呈线性时延
  • ipvs

    • 工作在内核空间
    • 优点
      • 转发效率高
      • 调度算法丰富:rr,wrr,lc,wlc,ip hash…
    • 缺点
      • 内核支持不全,低版本内核不能使用,需要升级到4.0或5.0以上。
  • 使用iptables与ipvs时机

    • 1.10版本之前使用iptables(1.1版本之前使用UserSpace进行转发)
    • 1.11版本之后同时支持iptables与ipvs,默认使用ipvs,如果ipvs模块没有加载时,会自动降级至iptables

三、 service类型

Service类型决定了访问Service的方法

3.1 service类型

  • ClusterIP

    • 默认,分配一个集群内部可以访问的虚拟IP
  • NodePort

    • 在每个Node上分配一个端口作为外部访问入口
    • nodePort端口范围为:30000-32767
  • LoadBalancer

    • 工作在特定的Cloud Provider上,例如Google Cloud,AWS,OpenStack
  • ExternalName

    • 表示把集群外部的服务引入到集群内部中来,即实现了集群内部pod和集群外部的服务进行通信

3.2 Service参数

  • port 访问service使用的端口

  • targetPort Pod中容器端口

  • nodePort 通过Node实现外网用户访问k8s集群内service (30000-32767)

四、 Service创建

Service的创建在工作中有两种方式,一是命令行创建,二是通过资源清单文件YAML文件创建。

4.1 ClusterIP类型

ClusterIP根据是否生成ClusterIP又可分为普通Service和Headless Service

Service两类:

  • 普通Service:

为Kubernetes的Service分配一个集群内部可访问的固定虚拟IP(Cluster IP), 实现集群内的访问。

  • Headless Service:

该服务不会分配Cluster IP, 也不通过kube-proxy做反向代理和负载均衡。而是通过DNS提供稳定的网络ID来访问,DNS会将headless service的后端直接解析为pod IP列表。

kubernetes核心概念 Service_第7张图片

4.1.1 普通ClusterIP Service创建

4.1.1.1 命令行创建Service

  • 创建Deployment类型的应用
[root@k8s-master01 ~]# cat 01_create_deployment_app_nginx.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-server1
spec:
  replicas: 2
  selector:
    matchLabels:
      app: nginx
  template:
     metadata:
       labels:
         app: nginx
     spec:
       containers:
       - name: c1
         image: nginx:1.15-alpine
         imagePullPolicy: IfNotPresent
         ports:
         - containerPort: 80
  • 应用资源清单文件
[root@k8s-master01 ~]# kubectl apply -f 01_create_deployment_app_nginx.yaml
  • 验证Deployment类型的创建情况
[root@k8s-master01 ~]# kubectl get deployment.apps
NAME            READY   UP-TO-DATE   AVAILABLE   AGE
nginx-server1   2/2     2            2           13s
  • 创建ClusterIP类型service与Deployment类型应用关联
命令创建service
[root@k8s-master01 ~]# kubectl expose deployment.apps nginx-server1 --type=ClusterIP --target-port=80 --port=80
service/nginx-server1 exposed
说明
expose 创建service
deployment.apps 控制器类型
nginx-server1 应用名称,也是service名称
--type=ClusterIP 指定service类型
--target-port=80 指定Pod中容器端口
--port=80 指定service端口

4.1.1.2 通过资源清单文件创建Service

[root@k8s-master01 ~]# cat 02_create_deployment_app_nginx_with_service.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-server1
spec:
  replicas: 2
  selector:
    matchLabels:
      app: nginx
  template:
     metadata:
       labels:
         app: nginx
     spec:
       containers:
       - name: nginx-smart
         image: nginx:1.15-alpine
         imagePullPolicy: IfNotPresent
         ports:
         - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: nginx-svc
spec:
  type: ClusterIP
  ports:
  - protocol: TCP
    port: 80
    targetPort: 80
  selector:
    app: nginx
[root@k8s-master01 ~]# kubectl  apply -f 02_create_deployment_app_nginx_with_service.yaml
  • 验证
查看service
[root@k8s-master01 ~]# kubectl get service
NAME         TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)    AGE
kubernetes   ClusterIP   10.96.0.1                443/TCP    4d15h
nginx-svc    ClusterIP   10.101.153.50            80/TCP    3s
查看endpoints
[root@k8s-master01 ~]# kubectl get endpoints
NAME         ENDPOINTS                            AGE
kubernetes   192.168.122.30:6443                  4d15h
nginx-svc    172.16.189.74:80,172.16.235.150:80   8s
查看Pod
[root@k8s-master01 ~]# kubectl get pods -l app=nginx
NAME                             READY   STATUS    RESTARTS   AGE
nginx-server1-77d4c485d8-gsrmq   1/1     Running   0          12s
nginx-server1-77d4c485d8-mmc52   1/1     Running   0          12s

4.1.1.3 访问

[root@k8s-master01 ~]# curl http://10.101.153.50:80
<!DOCTYPE html>


Welcome to nginx!<<span class="token operator">/</span>title>
<style>
    body <span class="token punctuation">{</span>
        width: 35em<span class="token punctuation">;</span>
        margin: 0 auto<span class="token punctuation">;</span>
        font-family: Tahoma<span class="token punctuation">,</span> Verdana<span class="token punctuation">,</span> Arial<span class="token punctuation">,</span> sans-serif<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<<span class="token operator">/</span>style>
<<span class="token operator">/</span>head>
<body>
<h1>Welcome to nginx!<<span class="token operator">/</span>h1>
<p><span class="token keyword">If</span> you see this page<span class="token punctuation">,</span> the nginx web server is successfully installed and
working<span class="token punctuation">.</span> Further configuration is required<span class="token punctuation">.</span><<span class="token operator">/</span>p>

<p><span class="token keyword">For</span> online documentation and support please refer to
<a href=<span class="token string">"http://nginx.org/"</span>>nginx<span class="token punctuation">.</span>org<<span class="token operator">/</span>a><span class="token punctuation">.</span><br/>
Commercial support is available at
<a href=<span class="token string">"http://nginx.com/"</span>>nginx<span class="token punctuation">.</span>com<<span class="token operator">/</span>a><span class="token punctuation">.</span><<span class="token operator">/</span>p>

<p><em>Thank you <span class="token keyword">for</span> <span class="token keyword">using</span> nginx<span class="token punctuation">.</span><<span class="token operator">/</span>em><<span class="token operator">/</span>p>
<<span class="token operator">/</span>body>
<<span class="token operator">/</span>html>
</code></pre> 
  <h4>4.1.1.4 两个pod里做成不同的主页方便测试负载均衡</h4> 
  <pre><code class="prism language-powershell"><span class="token namespace">[root@k8s-master01 ~]</span><span class="token comment"># kubectl exec -it nginx-server1-77d4c485d8-gsrmq -- /bin/bash</span>
root@deployment-nginx-6fcfb67547-nv7dn:<span class="token operator">/</span><span class="token comment"># cd /usr/share/nginx/html/</span>
root@deployment-nginx-6fcfb67547-nv7dn:<span class="token operator">/</span>usr/share/nginx/html<span class="token comment"># echo web1 > index.html</span>
root@deployment-nginx-6fcfb67547-nv7dn:<span class="token operator">/</span>usr/share/nginx/html<span class="token comment"># exit</span>
<span class="token keyword">exit</span>
</code></pre> 
  <pre><code class="prism language-powershell"><span class="token namespace">[root@k8s-master01 ~]</span><span class="token comment"># kubectl exec -it nginx-server1-77d4c485d8-mmc52 -- /bin/bash</span>
root@deployment-nginx-6fcfb67547-rqrcw:<span class="token operator">/</span><span class="token comment"># cd /usr/share/nginx/html/</span>
root@deployment-nginx-6fcfb67547-rqrcw:<span class="token operator">/</span>usr/share/nginx/html<span class="token comment"># echo web2 > index.html</span>
root@deployment-nginx-6fcfb67547-rqrcw:<span class="token operator">/</span>usr/share/nginx/html<span class="token comment"># exit</span>
<span class="token keyword">exit</span>
</code></pre> 
  <h4>4.1.1.5 测试</h4> 
  <pre><code class="prism language-powershell"><span class="token namespace">[root@k8s-master01 ~]</span><span class="token comment"># curl 10.101.153.50</span>
或
<span class="token namespace">[root@k8s-master01 ~]</span><span class="token comment"># while true;do curl 10.101.153.50;sleep 1; done</span>
</code></pre> 
  <h3>4.1.2 Headless Service</h3> 
  <ul> 
   <li>普通的ClusterIP service是service name解析为cluster ip,然后cluster ip对应到后面的pod ip</li> 
   <li>Headless service是指service name 直接解析为后面的pod ip</li> 
  </ul> 
  <h4>4.1.2.1 编写用于创建Deployment控制器类型的资源清单文件</h4> 
  <pre><code class="prism language-powershell"><span class="token namespace">[root@k8s-master01 ~]</span><span class="token comment"># cat 03_create_deployment_app_nginx.yaml</span>
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-server1
spec:
  replicas: 2
  selector:
    matchLabels:
      app: nginx
  template:
     metadata:
       labels:
         app: nginx
     spec:
       containers:
       <span class="token operator">-</span> name: nginx-smart
         image: nginx:1<span class="token punctuation">.</span>15-alpine
         imagePullPolicy: IfNotPresent
         ports:
         <span class="token operator">-</span> containerPort: 80
</code></pre> 
  <h4>4.1.2.2 通过资源清单文件创建headless Service</h4> 
  <pre><code class="prism language-powershell">编写YAML文件
命令
<span class="token namespace">[root@k8s-master01 ~]</span><span class="token comment"># vim 04_headless-service.yml</span>
apiVersion: v1
kind: Service
metadata:
  name: headless-service
  namespace: default
spec:
  <span class="token function">type</span>: ClusterIP     <span class="token comment"># ClusterIP类型,也是默认类型</span>
  clusterIP: None     <span class="token comment"># None就代表是无头service</span>
  ports:                                <span class="token comment"># 指定service 端口及容器端口</span>
  <span class="token operator">-</span> port: 80                            <span class="token comment"># service ip中的端口</span>
    protocol: TCP
    targetPort: 80                      <span class="token comment"># pod中的端口</span>
  selector:                             <span class="token comment"># 指定后端pod标签</span>
     app: nginx                         <span class="token comment"># 可通过kubectl get pod -l app=nginx查看哪些pod在使用此标签</span>
</code></pre> 
  <h4>4.1.2.3 应用资源清单文件创建headless Service</h4> 
  <pre><code class="prism language-powershell">命令
<span class="token namespace">[root@k8s-master01 ~]</span><span class="token comment"># kubectl apply -f 04_headless_service.yml</span>
输出
service/headless-service created
</code></pre> 
  <h4>4.1.2.4 查看已创建的headless Service</h4> 
  <pre><code class="prism language-powershell">命令
<span class="token namespace">[root@k8s-master01 ~]</span><span class="token comment"># kubectl get svc</span>
输出
NAME               <span class="token function">TYPE</span>        CLUSTER-IP       EXTERNAL-IP   PORT<span class="token punctuation">(</span>S<span class="token punctuation">)</span>          AGE
headless-service   ClusterIP   None             <none>        80/TCP           2m18s
kubernetes         ClusterIP   10<span class="token punctuation">.</span>96<span class="token punctuation">.</span>0<span class="token punctuation">.</span>1        <none>        443/TCP          5d9h
可以看到headless-service没有CLUSTER-IP<span class="token punctuation">,</span>用None表示
</code></pre> 
  <h4>4.1.2.5 DNS</h4> 
  <p>DNS服务监视Kubernetes API,为每一个Service创建DNS记录用于域名解析</p> 
  <p>headless service需要DNS来解决访问问题</p> 
  <p>DNS记录格式为:<code> <service-name>.<namespace-name>.svc.cluster.local.</code></p> 
  <h5>4.1.2.5.1 查看kube-dns服务的IP</h5> 
  <pre><code class="prism language-powershell">命令
<span class="token namespace">[root@k8s-master01 ~]</span><span class="token comment"># kubectl get svc -n kube-system</span>
NAME             <span class="token function">TYPE</span>        CLUSTER-IP      EXTERNAL-IP   PORT<span class="token punctuation">(</span>S<span class="token punctuation">)</span>                  AGE
kube-dns         ClusterIP   10<span class="token punctuation">.</span>96<span class="token punctuation">.</span>0<span class="token punctuation">.</span>2      <none>        53/UDP<span class="token punctuation">,</span>53/TCP<span class="token punctuation">,</span>9153/TCP   5d9h
metrics-server   ClusterIP   10<span class="token punctuation">.</span>105<span class="token punctuation">.</span>219<span class="token punctuation">.</span>44   <none>        443/TCP                  45h
查看到coreDNS的服务地址是10<span class="token punctuation">.</span>96<span class="token punctuation">.</span>0<span class="token punctuation">.</span>2
</code></pre> 
  <h5>4.1.2.5.2 在集群主机通过DNS服务地址查找无头服务的dns解析</h5> 
  <pre><code class="prism language-powershell"><span class="token namespace">[root@k8s-master01 ~]</span><span class="token comment"># dig -t A headless-service.default.svc.cluster.local. @10.96.0.2</span>
<span class="token punctuation">;</span> <<>> DiG 9<span class="token punctuation">.</span>11<span class="token punctuation">.</span>4-P2-RedHat-9<span class="token punctuation">.</span>11<span class="token punctuation">.</span>4-16<span class="token punctuation">.</span>P2<span class="token punctuation">.</span>el7_8<span class="token punctuation">.</span>2 <<>> <span class="token operator">-</span>t A headless-service<span class="token punctuation">.</span>default<span class="token punctuation">.</span>svc<span class="token punctuation">.</span>cluster<span class="token punctuation">.</span>local<span class="token punctuation">.</span> @10<span class="token punctuation">.</span>96<span class="token punctuation">.</span>0<span class="token punctuation">.</span>2
<span class="token punctuation">;</span><span class="token punctuation">;</span> global options: <span class="token operator">+</span>cmd
<span class="token punctuation">;</span><span class="token punctuation">;</span> Got answer:
<span class="token punctuation">;</span><span class="token punctuation">;</span> WARNING: <span class="token punctuation">.</span>local is reserved <span class="token keyword">for</span> Multicast DNS
<span class="token punctuation">;</span><span class="token punctuation">;</span> You are currently testing what happens when an mDNS query is leaked to DNS
<span class="token punctuation">;</span><span class="token punctuation">;</span> <span class="token operator">-</span>>>HEADER<<<span class="token operator">-</span> opcode: QUERY<span class="token punctuation">,</span> status: NOERROR<span class="token punctuation">,</span> id: 31371
<span class="token punctuation">;</span><span class="token punctuation">;</span> flags: qr aa <span class="token function">rd</span><span class="token punctuation">;</span> QUERY: 1<span class="token punctuation">,</span> ANSWER: 1<span class="token punctuation">,</span> AUTHORITY: 0<span class="token punctuation">,</span> ADDITIONAL: 1
<span class="token punctuation">;</span><span class="token punctuation">;</span> WARNING: recursion requested but not available

<span class="token punctuation">;</span><span class="token punctuation">;</span> OPT PSEUDOSECTION:
<span class="token punctuation">;</span> EDNS: version: 0<span class="token punctuation">,</span> flags:<span class="token punctuation">;</span> udp: 4096
<span class="token punctuation">;</span><span class="token punctuation">;</span> QUESTION SECTION:
<span class="token punctuation">;</span>headless-service<span class="token punctuation">.</span>default<span class="token punctuation">.</span>svc<span class="token punctuation">.</span>cluster<span class="token punctuation">.</span>local<span class="token punctuation">.</span> IN A <span class="token comment">#被解析域名</span>

<span class="token punctuation">;</span><span class="token punctuation">;</span> ANSWER SECTION:
headless-service<span class="token punctuation">.</span>default<span class="token punctuation">.</span>svc<span class="token punctuation">.</span>cluster<span class="token punctuation">.</span>local<span class="token punctuation">.</span> 30 IN A 10<span class="token punctuation">.</span>224<span class="token punctuation">.</span>235<span class="token punctuation">.</span>147 <span class="token comment">#注意这里IP</span>

<span class="token punctuation">;</span><span class="token punctuation">;</span> Query time: 0 msec
<span class="token punctuation">;</span><span class="token punctuation">;</span> SERVER: 10<span class="token punctuation">.</span>96<span class="token punctuation">.</span>0<span class="token punctuation">.</span>10<span class="token comment">#53(10.96.0.2)</span>
<span class="token punctuation">;</span><span class="token punctuation">;</span> WHEN: Sun May 17 10:58:50 CST 2020
<span class="token punctuation">;</span><span class="token punctuation">;</span> MSG SIZE  rcvd: 129
</code></pre> 
  <h5>4.1.2.5.3 验证pod的IP</h5> 
  <pre><code class="prism language-powershell"><span class="token namespace">[root@k8s-master01 ~]</span><span class="token comment"># kubectl get pod -o wide</span>
NAME                                READY   STATUS             RESTARTS   AGE   IP               NODE      NOMINATED NODE   READINESS GATES
nginx-deployment-56bf6c9c8c-jmk7r   1/1     Running            0          35m   10<span class="token punctuation">.</span>224<span class="token punctuation">.</span>235<span class="token punctuation">.</span>147   worker02   <none>           <none>
</code></pre> 
  <h5>4.1.2.5.4 在集群中创建一个pod验证</h5> 
  <blockquote> 
   <p>创建一个镜像为busyboxplus:curl的pod,pod名称为bb2,用来解析域名</p> 
  </blockquote> 
  <pre><code class="prism language-powershell"><span class="token namespace">[root@k8s-master01 ~]</span><span class="token comment"># kubectl run bbp --image=busyboxplus:curl -it</span>
<span class="token namespace">[root@master01 ~]</span><span class="token comment"># kubectl run bbp --image=1.28 -it</span>
<span class="token keyword">If</span> you don<span class="token string">'t see a command prompt, try pressing enter.
解析域名
nslookup headless-service.default.svc.cluster.local.
访问命令
[ root@bbp:/ ]$ curl http://headless-service.default.svc.cluster.local.
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!



Welcome to nginx!

If you see this page, the nginx web server is successfully installed and working. Further configuration is required.

For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.

Thank you for using nginx.

[ root@bbp:/ ]$ exit Session ended, resume using 'kubectl attach bbp -c bbp -i -t' command when the pod is running

4.2 NodePort类型

  • 创建资源清单文件
[root@k8s-master01 ~]# cat 05_create_nodeport_service_app.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-app
  labels:
    app: nginx-app
spec:
  replicas: 2
  selector:
    matchLabels:
      app: nginx-app
  template:
    metadata:
      labels:
        app: nginx-app
    spec:
      containers:
      - name: c1
        image: nginx:1.15-alpine
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: nginx-app
spec:
  type: NodePort
  selector:
    app: nginx-app
  ports:
  - protocol: TCP
    nodePort: 30001
    port: 8060
    targetPort: 80
  • 应用资源清单文件
[root@k8s-master01 ~]# kubectl apply -f 05_create_nodeport_service_app.yaml
deployment.apps/nginx-app created
service/nginx-app created
  • 验证service创建
[root@k8s-master01 ~]# kubectl get deployment.apps
NAME         READY   UP-TO-DATE   AVAILABLE   AGE
nginx-app    2/2     2            2           26s
[root@k8s-master01 ~]# kubectl get svc
NAME         TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
kubernetes   ClusterIP   10.96.0.1                443/TCP          2d22h
nginx-app    NodePort    10.104.157.20            8060:30001/TCP   36s
[root@k8s-master01 ~]# kubectl get endpoints
NAME         ENDPOINTS                       AGE
kubernetes   192.168.122.10:6443             2d22h
nginx-app    172.16.1.24:80,172.16.2.20:80   2m10s
[root@master01 ~]# ss -anput | grep ":30001"
tcp    LISTEN     0      128      :::30001                :::*                   users:(("kube-proxy",pid=5826,fd=9))
[root@worker01 ~]# ss -anput | grep ":30001"
tcp    LISTEN     0      128      :::30001                :::*                   users:(("kube-proxy",pid=4937,fd=11))
[root@worker02 ~]# ss -anput | grep ":30001"
tcp    LISTEN     0      128      :::30001                :::*                   users:(("kube-proxy",pid=5253,fd=11))
[root@k8s-master01 ~]# kubectl get pods
NAME                          READY   STATUS    RESTARTS   AGE
nginx-app-ffd5ccc78-cnwbx    1/1     Running   0          8m59s
nginx-app-ffd5ccc78-mz77g    1/1     Running   0          8m59s
[root@k8s-master01 ~]# kubectl exec -it nginx-app-ffd5ccc78-cnwbx -- bash
root@nginx-app-ffd5ccc78-cnwbx:/# echo "nginx-app-1" > /usr/share/nginx/html/index.html
root@nginx-app-ffd5ccc78-cnwbx:/# exit
[root@k8s-master01 ~]# kubectl exec -it nginx-app-ffd5ccc78-mz77g -- bash
root@nginx-app-ffd5ccc78-mz77g:/# echo "nginx-app-2" > /usr/share/nginx/html/index.html
root@nginx-app-ffd5ccc78-mz77g:/# exit
  • 在与kubernetes 节点同一网络主机中访问k8s集群内service
[root@ha1 ~]# curl http://192.168.10.101:30001
nginx-app-2
[root@ha1 ~]# curl http://192.168.10.102:30001
nginx-app-1
[root@ha1 ~]# curl http://192.168.10.103:30001
nginx-app-1
[root@ha1 ~]# curl http://192.168.10.104:30001
nginx-app-2

4.3 LoadBalancer

4.3.1 集群外访问过程

  • 用户

  • 域名

  • 云服务提供商提供LB服务

  • NodeIP:Port(service IP)

  • Pod IP:端口

kubernetes核心概念 Service_第8张图片

4.3.2 自建Kubernetes的LoadBalancer类型服务方案-MetalLB

MetalLB可以为kubernetes集群中的Service提供网络负载均衡功能。

MetalLB两大功能为:

  • 地址分配,类似于DHCP
  • 外部通告,一旦MetalLB为服务分配了外部IP地址,它就需要使集群之外的网络意识到该IP在群集中“存在”。MetalLB使用标准路由协议来实现此目的:ARP,NDP或BGP。

4.3.2.1 参考资料

参考网址: https://metallb.universe.tf/installation/

4.3.2.2 应用资源清单文件

资源清单文件下载:
# kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.12.1/manifests/namespace.yaml
# kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.12.1/manifests/metallb.yaml

4.3.2.3 准备metallb配置文件

[root@k8s-master01 metallb]# cat metallb-conf.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  namespace: metallb-system
  name: config
data:
  config: |
    address-pools:
    - name: default
      protocol: layer2
      addresses:
      - 192.168.10.100-192.168.10.120
集群节点服务器IP同一段。
在master01节点应用资源清单文件
[root@k8s-master01 ~]# kubectl apply -f metallb-conf.yaml	
验证配置
# kubectl describe configmap config -n metallb-system
Name:         config
Namespace:    metallb-system
Labels:       
Annotations:  

Data
====
config:
----
address-pools:
- name: default
  protocol: layer2
  addresses:
  - 192.168.10.100-192.168.10.120
Events:  

4.3.2.4发布Service类型为LoadBalancer的Deployment控制器类型应用

创建Deployment控制器类型应用nginx-metallb及service,service类型为LoadBalancer
[root@k8s-master01 ~]# vim 02_nginx-metabllb.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-metallb
spec:
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx-metallb1
        image: nginx:1.15-alpine
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: nginx-metallb
spec:
  ports:
  - port: 8090
    protocol: TCP
    targetPort: 80
  selector:
    app: nginx
  type: LoadBalancer
[root@k8s-master01 ~]# kubectl apply -f nginx.yaml

4.3.2.5 验证

[root@k8s-master01 ~]# kubectl get ns
NAME                   STATUS   AGE
default                Active   16d
kube-node-lease        Active   16d
kube-public            Active   16d
kube-system            Active   16d
kubernetes-dashboard   Active   13d
metallb-system         Active   130m
test1                  Active   12d
[root@k8s-master01 ~]# kubectl get pods -n metallb-system
NAME                         READY   STATUS    RESTARTS   AGE
controller-64f8f944d-qdf8m   1/1     Running   0          110m
speaker-cwzq7                1/1     Running   0          110m
speaker-qk5fb                1/1     Running   0          110m
speaker-wsllb                1/1     Running   0          110m
speaker-x4bwt                1/1     Running   0          110m
[root@k8s-master01 ~]# kubectl get svc
NAME            TYPE           CLUSTER-IP      EXTERNAL-IP      PORT(S)          AGE
kubernetes      ClusterIP      10.96.0.1                  443/TCP          16d
nginx-metallb   LoadBalancer   10.105.239.69   192.168.10.115   8090:31372/TCP   106m
[root@k8s-master01 ~]# ping 192.168.10.115
PING 192.168.10.90 (192.168.10.90) 56(84) bytes of data.
64 bytes from 192.168.10.90: icmp_seq=1 ttl=64 time=3.45 ms
64 bytes from 192.168.10.90: icmp_seq=2 ttl=64 time=0.040 ms

4.3.2.6 访问

[root@k8s-master01 ~]# curl http://192.168.122.115:8090
<!DOCTYPE html>


Welcome to nginx!<<span class="token operator">/</span>title>
<style>
    body <span class="token punctuation">{</span>
        width: 35em<span class="token punctuation">;</span>
        margin: 0 auto<span class="token punctuation">;</span>
        font-family: Tahoma<span class="token punctuation">,</span> Verdana<span class="token punctuation">,</span> Arial<span class="token punctuation">,</span> sans-serif<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<<span class="token operator">/</span>style>
<<span class="token operator">/</span>head>
<body>
<h1>Welcome to nginx!<<span class="token operator">/</span>h1>
<p><span class="token keyword">If</span> you see this page<span class="token punctuation">,</span> the nginx web server is successfully installed and
working<span class="token punctuation">.</span> Further configuration is required<span class="token punctuation">.</span><<span class="token operator">/</span>p>

<p><span class="token keyword">For</span> online documentation and support please refer to
<a href=<span class="token string">"http://nginx.org/"</span>>nginx<span class="token punctuation">.</span>org<<span class="token operator">/</span>a><span class="token punctuation">.</span><br/>
Commercial support is available at
<a href=<span class="token string">"http://nginx.com/"</span>>nginx<span class="token punctuation">.</span>com<<span class="token operator">/</span>a><span class="token punctuation">.</span><<span class="token operator">/</span>p>

<p><em>Thank you <span class="token keyword">for</span> <span class="token keyword">using</span> nginx<span class="token punctuation">.</span><<span class="token operator">/</span>em><<span class="token operator">/</span>p>
<<span class="token operator">/</span>body>
<<span class="token operator">/</span>html>
</code></pre> 
  <p><strong>注意:使用kubeadm部署kubernetes集群修改方法</strong></p> 
  <pre><code class="prism language-powershell">如果在IPVS模式下使用kube-proxy,从Kubernetes v1<span class="token punctuation">.</span>14<span class="token punctuation">.</span>2开始,必须启用ARP模式。
可以通过在当前集群中编辑kube-proxy配置来实现:
<span class="token comment"># kubectl edit configmap -n kube-system kube-proxy</span>
并设置:
apiVersion: kubeproxy<span class="token punctuation">.</span>config<span class="token punctuation">.</span>k8s<span class="token punctuation">.</span>io/v1alpha1
kind: KubeProxyConfiguration
mode: <span class="token string">"ipvs"</span>
ipvs:
  strictARP: true
</code></pre> 
  <h2>4.4 ExternalName</h2> 
  <h3>4.4.1 ExternalName作用</h3> 
  <ul> 
   <li>把集群外部的服务引入到集群内部中来,实现了集群内部pod和集群外部的服务进行通信</li> 
   <li>ExternalName 类型的服务适用于外部服务使用域名的方式,缺点是不能指定端口</li> 
   <li>还有一点要注意: 集群内的Pod会继承Node上的DNS解析规则。所以只要Node可以访问的服务,Pod中也可以访问到, 这就实现了集群内服务访问集群外服务</li> 
  </ul> 
  <h3>4.4.2 将公网域名引入</h3> 
  <ol> 
   <li>编写YAML文件</li> 
  </ol> 
  <pre><code class="prism language-powershell"> <span class="token namespace">[root@k8s-master01 ~]</span><span class="token comment"># vim externelname.yml</span>
 apiVersion: v1
kind: Service
metadata:
  name: my-externalname
  namespace: default
spec:
  <span class="token function">type</span>: ExternalName
  externalName: www<span class="token punctuation">.</span>baidu<span class="token punctuation">.</span>com                  <span class="token comment"># 对应的外部域名为www.baidu.com</span>
</code></pre> 
  <ol start="2"> 
   <li>应用YAML文件</li> 
  </ol> 
  <pre><code class="prism language-powershell"> <span class="token namespace">[root@k8s-master01 ~]</span><span class="token comment"># kubectl apply -f externelname.yml</span>
 service/my-externalname created
</code></pre> 
  <ol start="3"> 
   <li>查看service</li> 
  </ol> 
  <pre><code class="prism language-powershell"> <span class="token namespace">[root@k8s-master01 ~]</span><span class="token comment"># kubectl get svc |grep exter</span>
 my-externalname    ExternalName   <none>         www<span class="token punctuation">.</span>baidu<span class="token punctuation">.</span>com   <none>         69s
</code></pre> 
  <ol start="4"> 
   <li>查看my-service的dns解析</li> 
  </ol> 
  <pre><code class="prism language-powershell"> <span class="token namespace">[root@k8s-master01 ~]</span><span class="token comment"># dig -t A my-externalname.default.svc.cluster.local. @10.96.0.2</span>
  <span class="token punctuation">;</span> <<>> DiG 9<span class="token punctuation">.</span>9<span class="token punctuation">.</span>4-RedHat-9<span class="token punctuation">.</span>9<span class="token punctuation">.</span>4-72<span class="token punctuation">.</span>el7 <<>> <span class="token operator">-</span>t A my-externalname<span class="token punctuation">.</span>default<span class="token punctuation">.</span>svc<span class="token punctuation">.</span>cluster<span class="token punctuation">.</span>local<span class="token punctuation">.</span> @10<span class="token punctuation">.</span>2<span class="token punctuation">.</span>0<span class="token punctuation">.</span>2
 <span class="token punctuation">;</span><span class="token punctuation">;</span> global options: <span class="token operator">+</span>cmd
 <span class="token punctuation">;</span><span class="token punctuation">;</span> Got answer:
 <span class="token punctuation">;</span><span class="token punctuation">;</span> <span class="token operator">-</span>>>HEADER<<<span class="token operator">-</span> opcode: QUERY<span class="token punctuation">,</span> status: NOERROR<span class="token punctuation">,</span> id: 31378
 <span class="token punctuation">;</span><span class="token punctuation">;</span> flags: qr aa <span class="token function">rd</span><span class="token punctuation">;</span> QUERY: 1<span class="token punctuation">,</span> ANSWER: 4<span class="token punctuation">,</span> AUTHORITY: 0<span class="token punctuation">,</span> ADDITIONAL: 1
 <span class="token punctuation">;</span><span class="token punctuation">;</span> WARNING: recursion requested but not available
 
 <span class="token punctuation">;</span><span class="token punctuation">;</span> OPT PSEUDOSECTION:
 <span class="token punctuation">;</span> EDNS: version: 0<span class="token punctuation">,</span> flags:<span class="token punctuation">;</span> udp: 4096
 <span class="token punctuation">;</span><span class="token punctuation">;</span> QUESTION SECTION:
 <span class="token punctuation">;</span>my-externalname<span class="token punctuation">.</span>default<span class="token punctuation">.</span>svc<span class="token punctuation">.</span>cluster<span class="token punctuation">.</span>local<span class="token punctuation">.</span> IN A
 
 <span class="token punctuation">;</span><span class="token punctuation">;</span> ANSWER SECTION:
 my-externalname<span class="token punctuation">.</span>default<span class="token punctuation">.</span>svc<span class="token punctuation">.</span>cluster<span class="token punctuation">.</span>local<span class="token punctuation">.</span> 5 IN CNAME www<span class="token punctuation">.</span>baidu<span class="token punctuation">.</span>com<span class="token punctuation">.</span>
 www<span class="token punctuation">.</span>baidu<span class="token punctuation">.</span>com<span class="token punctuation">.</span>          5       IN      CNAME   www<span class="token punctuation">.</span>a<span class="token punctuation">.</span>shifen<span class="token punctuation">.</span>com<span class="token punctuation">.</span>
 www<span class="token punctuation">.</span>a<span class="token punctuation">.</span>shifen<span class="token punctuation">.</span>com<span class="token punctuation">.</span>       5       IN      A       14<span class="token punctuation">.</span>215<span class="token punctuation">.</span>177<span class="token punctuation">.</span>38           解析的是百度的IP
 www<span class="token punctuation">.</span>a<span class="token punctuation">.</span>shifen<span class="token punctuation">.</span>com<span class="token punctuation">.</span>       5       IN      A       14<span class="token punctuation">.</span>215<span class="token punctuation">.</span>177<span class="token punctuation">.</span>39           解析的是百度的IP
 
 <span class="token punctuation">;</span><span class="token punctuation">;</span> Query time: 32 msec
 <span class="token punctuation">;</span><span class="token punctuation">;</span> SERVER: 10<span class="token punctuation">.</span>2<span class="token punctuation">.</span>0<span class="token punctuation">.</span>2<span class="token comment">#53(10.96.0.2)</span>
 <span class="token punctuation">;</span><span class="token punctuation">;</span> WHEN: Thu Nov 05 11:23:41 CST 2020
 <span class="token punctuation">;</span><span class="token punctuation">;</span> MSG SIZE  rcvd: 245
</code></pre> 
  <pre><code class="prism language-powershell"> <span class="token namespace">[root@k8s-master01 ~]</span><span class="token comment"># kubectl exec -it deploy-nginx-6c9764bb69-86gwj -- /bin/sh</span>
 <span class="token operator">/</span> <span class="token comment"># nslookup www.baidu.com</span>
 <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>
 Name:      www<span class="token punctuation">.</span>baidu<span class="token punctuation">.</span>com
 Address 1: 14<span class="token punctuation">.</span>215<span class="token punctuation">.</span>177<span class="token punctuation">.</span>39
 Address 2: 14<span class="token punctuation">.</span>215<span class="token punctuation">.</span>177<span class="token punctuation">.</span>38
  
 <span class="token operator">/</span> <span class="token comment"># nslookup my-externalname.default.svc.cluster.local         </span>
 <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>
 Name:      my-externalname<span class="token punctuation">.</span>default<span class="token punctuation">.</span>svc<span class="token punctuation">.</span>cluster<span class="token punctuation">.</span>local
 Address 1: 14<span class="token punctuation">.</span>215<span class="token punctuation">.</span>177<span class="token punctuation">.</span>38
 Address 2: 14<span class="token punctuation">.</span>215<span class="token punctuation">.</span>177<span class="token punctuation">.</span>39
</code></pre> 
  <p>解析此<code>my-externalname.default.svc.cluster.local</code>域名和解析<code>www.baidu.com</code>是一样的结果</p> 
  <h3>4.4.3 不同命名空间访问</h3> 
  <ol> 
   <li>创建ns1命名空间和相关deploy, pod,service</li> 
  </ol> 
  <pre><code class="prism language-powershell"> <span class="token namespace">[root@k8s-master01 ~]</span><span class="token comment"># vim ns1-nginx.yml</span>
apiVersion: v1                                                  
kind: Namespace                                                 
metadata:                                                             
  name: ns1                                                     <span class="token comment"># 创建ns1命名空间</span>
<span class="token operator">--</span><span class="token operator">-</span>
apiVersion: apps/v1
kind: Deployment
metadata:
  name: deploy-nginx                    
  namespace: ns1                                                <span class="token comment"># 属于ns1命名空间</span>
spec:
  replicas: 1                                  
  selector:
    matchLabels:
      app: nginx                                
  template:                                        
    metadata:
      labels:
        app: nginx                             
    spec:
      containers:                              
      <span class="token operator">-</span> name: nginx
        image: nginx:1<span class="token punctuation">.</span>15-alpine
        imagePullPolicy: IfNotPresent
        ports:
        <span class="token operator">-</span> containerPort: 80
<span class="token operator">--</span><span class="token operator">-</span>
apiVersion: v1
kind: Service
metadata:
  name: svc1                                <span class="token comment"># 服务名</span>
  namespace: ns1                            <span class="token comment"># 属于ns1命名空间</span>
spec:
  selector:
    app: nginx
  clusterIP: None                           <span class="token comment"># 无头service</span>
  ports:
  <span class="token operator">-</span> port: 80                         
    targetPort: 80                  
<span class="token operator">--</span><span class="token operator">-</span>
kind: Service
apiVersion: v1
metadata:
  name: external-svc1
  namespace: ns1                            <span class="token comment">#  属于ns1命名空间</span>
spec:
  <span class="token function">type</span>: ExternalName
  externalName: svc2<span class="token punctuation">.</span>ns2<span class="token punctuation">.</span>svc<span class="token punctuation">.</span>cluster<span class="token punctuation">.</span>local   <span class="token comment"># 将ns2空间的svc2服务引入到ns1命名空间   </span>
 <span class="token namespace">[root@k8s-master1 ~]</span><span class="token comment"># kubectl apply -f ns1-nginx.yml</span>
 namespace/ns1 created
 deployment<span class="token punctuation">.</span>apps/deploy-nginx created
 service/svc1 created
</code></pre> 
  <ol start="2"> 
   <li>创建ns2命名空间和相关deploy, pod,service</li> 
  </ol> 
  <pre><code class="prism language-powershell"><span class="token namespace">[root@k8s-master01 ~]</span><span class="token comment"># vim ns1-nginx.yml</span>
apiVersion: v1                                                  
kind: Namespace                                                 
metadata:                                                             
  name: ns2                                                     <span class="token comment"># 创建ns2命名空间</span>
<span class="token operator">--</span><span class="token operator">-</span>
apiVersion: apps/v1
kind: Deployment
metadata:
  name: deploy-nginx                    
  namespace: ns2                                                <span class="token comment"># 属于ns2命名空间</span>
spec:
  replicas: 1                                  
  selector:
    matchLabels:
      app: nginx                                
  template:                                        
    metadata:
      labels:
        app: nginx                             
    spec:
      containers:                              
      <span class="token operator">-</span> name: nginx
        image: nginx:1<span class="token punctuation">.</span>15-alpine
        imagePullPolicy: IfNotPresent
        ports:
        <span class="token operator">-</span> containerPort: 80
<span class="token operator">--</span><span class="token operator">-</span>
apiVersion: v1
kind: Service
metadata:
  name: svc2                                <span class="token comment"># 服务名</span>
  namespace: ns2                            <span class="token comment"># 属于ns2命名空间</span>
spec:
  selector:
    app: nginx
  clusterIP: None                           <span class="token comment"># 无头service</span>
  ports:
  <span class="token operator">-</span> port: 80                         
    targetPort: 80                  
<span class="token operator">--</span><span class="token operator">-</span>
kind: Service
apiVersion: v1
metadata:
  name: external-svc1
  namespace: ns2                            <span class="token comment">#  属于ns2命名空间</span>
spec:
  <span class="token function">type</span>: ExternalName
  externalName: svc1<span class="token punctuation">.</span>ns1<span class="token punctuation">.</span>svc<span class="token punctuation">.</span>cluster<span class="token punctuation">.</span>local   <span class="token comment"># 将ns1空间的svc1服务引入到ns2命名空间</span>
</code></pre> 
  <pre><code class="prism language-powershell"> <span class="token namespace">[root@k8s-master01 ~]</span><span class="token comment"># kubectl apply -f ns2-nginx.yml</span>
 namespace/ns2 created
 deployment<span class="token punctuation">.</span>apps/deploy-nginx created
 service/svc2 created
 service/external-svc2 created
</code></pre> 
  <ol start="3"> 
   <li>在ns1命名空间的pod里验证</li> 
  </ol> 
  <pre><code class="prism language-powershell"> <span class="token namespace">[root@k8s-master01 ~]</span><span class="token comment"># kubectl get pods -n ns1</span>
 NAME                            READY   STATUS    RESTARTS   AGE
 deploy-nginx-6c9764bb69-g5xl8   1/1     Running   0          8m10s
</code></pre> 
  <pre><code class="prism language-powershell"> <span class="token namespace">[root@k8s-master01 ~]</span><span class="token comment"># kubectl exec -it -n ns1 deploy-nginx-6c9764bb69-g5xl8 -- /bin/sh</span>
 <span class="token operator">/</span> <span class="token comment"># nslookup svc1</span>
 <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>
 Name:      svc1
 Address 1: 10<span class="token punctuation">.</span>3<span class="token punctuation">.</span>166<span class="token punctuation">.</span>140 deploy-nginx-6c9764bb69-g5xl8       IP与ns1里的podIP一致<span class="token punctuation">(</span>见下面的查询结果<span class="token punctuation">)</span>
  <span class="token operator">/</span> <span class="token comment"># nslookup svc2.ns2.svc.cluster.local</span>
 <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>
 Name:      svc2<span class="token punctuation">.</span>ns2<span class="token punctuation">.</span>svc<span class="token punctuation">.</span>cluster<span class="token punctuation">.</span>local
 Address 1: 10<span class="token punctuation">.</span>3<span class="token punctuation">.</span>104<span class="token punctuation">.</span>17 10-3-104-17<span class="token punctuation">.</span>svc2<span class="token punctuation">.</span>ns2<span class="token punctuation">.</span>svc<span class="token punctuation">.</span>cluster<span class="token punctuation">.</span>local   IP与ns2里的podIP一致<span class="token punctuation">(</span>见下面的查询结果<span class="token punctuation">)</span>
  <span class="token operator">/</span> <span class="token comment"># exit</span>
</code></pre> 
  <pre><code class="prism language-powershell"> <span class="token namespace">[root@k8s-master01 ~]</span><span class="token comment"># kubectl get pods -o wide -n ns1</span>
 NAME                            READY   STATUS    RESTARTS   AGE   IP             NODE             NOMINATED NODE   READINESS GATES
 deploy-nginx-6c9764bb69-g5xl8   1/1     Running   0          70m   10<span class="token punctuation">.</span>3<span class="token punctuation">.</span>166<span class="token punctuation">.</span>140   192<span class="token punctuation">.</span>168<span class="token punctuation">.</span>122<span class="token punctuation">.</span>13   <none>           <none>
 <span class="token namespace">[root@k8s-master01 ~]</span><span class="token comment"># kubectl get pods -o wide -n ns2</span>
 NAME                            READY   STATUS    RESTARTS   AGE   IP            NODE             NOMINATED NODE   READI            NESS GATES
 deploy-nginx-6c9764bb69-8psxl   1/1     Running   0          68m   10<span class="token punctuation">.</span>3<span class="token punctuation">.</span>104<span class="token punctuation">.</span>17   192<span class="token punctuation">.</span>168<span class="token punctuation">.</span>122<span class="token punctuation">.</span>14   <none>           <none>
</code></pre> 
  <p>反之,在ns2命名空间的pod里访问<code>svc1.ns1.svc.cluster.local</code>,解析的IP是ns1命名空间里的pod的IP(请自行验证)</p> 
  <ol start="4"> 
   <li>验证ns2中的pod的IP变化, ns1中的pod仍然可以使用<code>svc2.ns2.svc.cluster.local</code>访问</li> 
  </ol> 
  <pre><code class="prism language-powershell"> <span class="token namespace">[root@k8s-master01 ~]</span><span class="token comment"># kubectl get pod -n ns2</span>
 NAME                            READY   STATUS    RESTARTS   AGE
 deploy-nginx-6c9764bb69-8psxl   1/1     Running   0          81m
 <span class="token namespace">[root@k8s-master01 ~]</span><span class="token comment"># kubectl delete pod deploy-nginx-6c9764bb69-8psxl -n ns2</span>
 pod <span class="token string">"deploy-nginx-6c9764bb69-8psxl"</span> deleted                   因为有replicas控制器,所以删除pod会自动拉一个起来
 <span class="token namespace">[root@k8s-master01 ~]</span><span class="token comment"># kubectl get pod -o wide -n ns2</span>
 NAME                            READY   STATUS    RESTARTS   AGE     IP             NODE             NOMINATED NODE   READINESS GATES
 deploy-nginx-6c9764bb69-8qbz2   1/1     Running   0          5m36s   10<span class="token punctuation">.</span>3<span class="token punctuation">.</span>166<span class="token punctuation">.</span>141   192<span class="token punctuation">.</span>168<span class="token punctuation">.</span>122<span class="token punctuation">.</span>13   <none>           <none>
 pod名称变了<span class="token punctuation">,</span>IP也变成了10<span class="token punctuation">.</span>3<span class="token punctuation">.</span>166<span class="token punctuation">.</span>141
</code></pre> 
  <p>回到ns1中的pod验证</p> 
  <pre><code class="prism language-powershell"> <span class="token namespace">[root@k8s-master01 ~]</span><span class="token comment"># kubectl exec -it -n ns1 deploy-nginx-6c9764bb69-g5xl8 -- /bin/sh</span>
 
 <span class="token operator">/</span> <span class="token comment"># ping svc2.ns2.svc.cluster.local -c 2</span>
 PING svc2<span class="token punctuation">.</span>ns2<span class="token punctuation">.</span>svc<span class="token punctuation">.</span>cluster<span class="token punctuation">.</span>local <span class="token punctuation">(</span>10<span class="token punctuation">.</span>3<span class="token punctuation">.</span>166<span class="token punctuation">.</span>141<span class="token punctuation">)</span>: 56 <span class="token keyword">data</span> bytes    解析的IP就是ns2中pod的新IP
 64 bytes <span class="token keyword">from</span> 10<span class="token punctuation">.</span>3<span class="token punctuation">.</span>166<span class="token punctuation">.</span>141: seq=0 ttl=63 time=0<span class="token punctuation">.</span>181 ms
 64 bytes <span class="token keyword">from</span> 10<span class="token punctuation">.</span>3<span class="token punctuation">.</span>166<span class="token punctuation">.</span>141: seq=1 ttl=63 time=0<span class="token punctuation">.</span>186 ms
 
 <span class="token operator">--</span><span class="token operator">-</span> svc2<span class="token punctuation">.</span>ns2<span class="token punctuation">.</span>svc<span class="token punctuation">.</span>cluster<span class="token punctuation">.</span>local ping statistics <span class="token operator">--</span><span class="token operator">-</span>
 2 packets transmitted<span class="token punctuation">,</span> 2 packets received<span class="token punctuation">,</span> 0% packet loss
 round-trip min/avg/max = 0<span class="token punctuation">.</span>181/0<span class="token punctuation">.</span>183/0<span class="token punctuation">.</span>186 ms
 <span class="token operator">/</span> <span class="token comment"># exit</span>
 
</code></pre> 
  <h1>五、sessionAffinity</h1> 
  <blockquote> 
   <p>会话粘贴</p> 
  </blockquote> 
  <p>设置sessionAffinity为Clientip (类似nginx的ip_hash算法,lvs的sh算法)</p> 
  <pre><code class="prism language-powershell"><span class="token namespace">[root@k8s-master01 ~]</span><span class="token comment"># cat 02_create_deployment_app_nginx_with_service.yaml</span>
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-server1
spec:
  replicas: 2
  selector:
    matchLabels:
      app: nginx
  template:
     metadata:
       labels:
         app: nginx
     spec:
       containers:
       <span class="token operator">-</span> name: c1
         image: nginx:1<span class="token punctuation">.</span>15-alpine
         imagePullPolicy: IfNotPresent
         ports:
         <span class="token operator">-</span> containerPort: 80
<span class="token operator">--</span><span class="token operator">-</span>
apiVersion: v1
kind: Service
metadata:
  name: nginx-svc
spec:
  <span class="token function">type</span>: ClusterIP
  ports:
  <span class="token operator">-</span> protocol: TCP
    port: 80
    targetPort: 80
  selector:
    app: nginx
</code></pre> 
  <pre><code class="prism language-powershell"><span class="token namespace">[root@k8s-master01 ~]</span><span class="token comment"># kubectl apply -f 02_create_deployment_app_nginx_with_service.yaml</span>
deployment<span class="token punctuation">.</span>apps/nginx-server1 created
service/nginx-svc created
</code></pre> 
  <pre><code class="prism language-powershell"><span class="token namespace">[root@k8s-master01 ~]</span><span class="token comment"># kubectl get pods</span>
NAME                             READY   STATUS    RESTARTS   AGE
nginx-server1-58845f75f4-9zlnw   1/1     Running   0          2m11s
nginx-server1-58845f75f4-ffqdt   1/1     Running   0          2m11s
<span class="token namespace">[root@k8s-master01 ~]</span><span class="token comment"># kubectl exec -it nginx-server1-58845f75f4-9zlnw bash</span>
kubectl exec <span class="token namespace">[POD]</span> <span class="token namespace">[COMMAND]</span> is DEPRECATED and will be removed in a future version<span class="token punctuation">.</span> Use kubectl kubectl exec <span class="token namespace">[POD]</span> <span class="token operator">--</span> <span class="token namespace">[COMMAND]</span> instead<span class="token punctuation">.</span>
root@nginx-server1-58845f75f4-9zlnw:<span class="token operator">/</span><span class="token comment"># echo web1 > /usr/share/nginx/html/index.html</span>
root@nginx-server1-58845f75f4-9zlnw:<span class="token operator">/</span><span class="token comment"># exit</span>
<span class="token keyword">exit</span>
<span class="token namespace">[root@k8s-master01 ~]</span><span class="token comment"># kubectl exec -it nginx-server1-58845f75f4-ffqdt bash</span>
kubectl exec <span class="token namespace">[POD]</span> <span class="token namespace">[COMMAND]</span> is DEPRECATED and will be removed in a future version<span class="token punctuation">.</span> Use kubectl kubectl exec <span class="token namespace">[POD]</span> <span class="token operator">--</span> <span class="token namespace">[COMMAND]</span> instead<span class="token punctuation">.</span>
root@nginx-server1-58845f75f4-ffqdt:<span class="token operator">/</span><span class="token comment"># echo web2 > /usr/share/nginx/html/index.html</span>
root@nginx-server1-58845f75f4-ffqdt:<span class="token operator">/</span><span class="token comment"># exit</span>
<span class="token keyword">exit</span>
</code></pre> 
  <pre><code class="prism language-powershell"><span class="token namespace">[root@k8s-master01 ~]</span><span class="token comment"># kubectl get svc</span>
NAME         <span class="token function">TYPE</span>        CLUSTER-IP     EXTERNAL-IP   PORT<span class="token punctuation">(</span>S<span class="token punctuation">)</span>   AGE
kubernetes   ClusterIP   10<span class="token punctuation">.</span>96<span class="token punctuation">.</span>0<span class="token punctuation">.</span>1      <none>        443/TCP   16d
nginx-svc    ClusterIP   10<span class="token punctuation">.</span>100<span class="token punctuation">.</span>53<span class="token punctuation">.</span>31   <none>        80/TCP    3m53s
<span class="token namespace">[root@k8s-master01 ~]</span><span class="token comment"># curl http://10.100.53.31</span>
web1
<span class="token namespace">[root@k8s-master01 ~]</span><span class="token comment"># curl http://10.100.53.31</span>
web2
或
<span class="token namespace">[root@k8s-master01 ~]</span><span class="token comment"># while true;do curl 10.100.53.31;sleep 1; done</span>
</code></pre> 
  <pre><code class="prism language-powershell"><span class="token namespace">[root@k8s-master01 ~]</span><span class="token comment"># kubectl patch svc nginx-svc -p '{"spec":{"sessionAffinity":"ClientIP"}}'</span>
service/nginx-svc patched
<span class="token namespace">[root@k8s-master01 ~]</span><span class="token comment"># curl 10.100.53.31</span>
web1
多次访问<span class="token punctuation">,</span>会话粘贴
</code></pre> 
  <pre><code class="prism language-powershell">设置回sessionAffinity为None
<span class="token namespace">[root@k8s-master01 ~]</span><span class="token comment"># kubectl patch svc nginx-svc -p '{"spec":{"sessionAffinity":"None"}}'</span>
service/my-service patched
</code></pre> 
  <pre><code class="prism language-powershell">测试
<span class="token namespace">[root@k8s-master01 ~]</span><span class="token comment"># curl 10.100.53.31</span>
web1
多次访问<span class="token punctuation">,</span>回到负载均衡
<span class="token namespace">[root@k8s-master01 ~]</span><span class="token comment"># while true;do curl 10.100.53.31;sleep 1; done</span>
web1
多次访问<span class="token punctuation">,</span>会话粘贴
</code></pre> 
  <h1>六、修改为ipvs调度方式(拓展)</h1> 
  <blockquote> 
   <p>部署方式不同,修改方法不一样。</p> 
   <p>本次主要介绍使用kubeadm部署集群方式,二进制部署较为简单。</p> 
   <p>二进制部署修改:/etc/kubernetes/kube-proxy.yaml文件即可。</p> 
  </blockquote> 
  <p>从kubernetes1.8版本开始,新增了kube-proxy对ipvs的支持,在kubernetes1.11版本中被纳入了GA.</p> 
  <h2>6.1 修改为IPVS调度方式前升级内核</h2> 
  <blockquote> 
   <p>现使用Centos7u6发布版本,默认内核版本为3.10.0,使用kubernetes为1.18.0时,可升级内核版本至4.18.0或5.6.0版本。</p> 
  </blockquote> 
  <blockquote> 
   <p>在所有节点中安装,需要重启操作系统更换内核。以下升级方法供参考。</p> 
  </blockquote> 
  <pre><code class="prism language-powershell"><span class="token namespace">[root@localhost ~]</span><span class="token comment"># yum -y install perl</span>
<span class="token namespace">[root@localhost ~]</span><span class="token comment"># rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org</span>
<span class="token namespace">[root@localhost ~]</span><span class="token comment"># yum -y install https://www.elrepo.org/elrepo-release-7.0-4.el7.elrepo.noarch.rpm</span>
<span class="token namespace">[root@localhost ~]</span><span class="token comment"># yum  --enablerepo="elrepo-kernel"  -y install kernel-ml.x86_64 </span>
此处升级为5<span class="token punctuation">.</span>0以上版本。
<span class="token namespace">[root@localhost ~]</span><span class="token comment"># grub2-set-default 0</span>
<span class="token namespace">[root@localhost ~]</span><span class="token comment"># grub2-mkconfig -o /boot/grub2/grub.cfg</span>
<span class="token namespace">[root@localhost ~]</span><span class="token comment"># reboot</span>
</code></pre> 
  <h2>6.2 修改kube-proxy的配置文件</h2> 
  <pre><code class="prism language-powershell"><span class="token namespace">[root@k8s-master01 ~]</span><span class="token comment"># kubectl edit configmap kube-proxy -n kube-system</span>
     26     iptables:
     27       masqueradeAll: false
     28       masqueradeBit: 14
     29       minSyncPeriod: 0s
     30       syncPeriod: 30s
     31     ipvs:
     32       excludeCIDRs: null
     33       minSyncPeriod: 0s
     34       scheduler: <span class="token string">""</span>	  <span class="token comment"># 可以在这里修改ipvs的算法,默认为rr轮循算法</span>
     35       strictARP: false
     36       syncPeriod: 30s
     37     kind: KubeProxyConfiguration
     38     metricsBindAddress: 127<span class="token punctuation">.</span>0<span class="token punctuation">.</span>0<span class="token punctuation">.</span>1:10249
     39     mode: <span class="token string">"ipvs"</span>	  <span class="token comment"># 默认""号里为空,加上ipvs</span>
</code></pre> 
  <h2>6.3 查看kube-system的namespace中kube-proxy有关的pod</h2> 
  <pre><code class="prism language-powershell"><span class="token namespace">[root@k8s-master01 ~]</span><span class="token comment"># kubectl get pods -n kube-system |grep kube-proxy</span>
kube-proxy-69mv6                           1/1     Running   6          2d18h
kube-proxy-jpc6c                           1/1     Running   4          4d16h
kube-proxy-kq65l                           1/1     Running   4          4d16h
kube-proxy-lmphf                           1/1     Running   5          4d16h
</code></pre> 
  <h2>6.4 验证kube-proxy-xxx的pod中的信息</h2> 
  <pre><code class="prism language-powershell"><span class="token namespace">[root@k8s-master01 ~]</span><span class="token comment"># kubectl logs kube-proxy-jpc6c -n kube-system</span>
W0517 00:55:10<span class="token punctuation">.</span>914754       1 server_others<span class="token punctuation">.</span>go:559<span class="token punctuation">]</span> Unknown proxy mode <span class="token string">""</span><span class="token punctuation">,</span> assuming iptables proxy
I0517 00:55:10<span class="token punctuation">.</span>923228       1 node<span class="token punctuation">.</span>go:136<span class="token punctuation">]</span> Successfully retrieved node IP: 192<span class="token punctuation">.</span>168<span class="token punctuation">.</span>122<span class="token punctuation">.</span>32
I0517 00:55:10<span class="token punctuation">.</span>923264       1 server_others<span class="token punctuation">.</span>go:186<span class="token punctuation">]</span> <span class="token keyword">Using</span> iptables Proxier<span class="token punctuation">.</span>
I0517 00:55:10<span class="token punctuation">.</span>923567       1 server<span class="token punctuation">.</span>go:583<span class="token punctuation">]</span> Version: v1<span class="token punctuation">.</span>18<span class="token punctuation">.</span>2
I0517 00:55:10<span class="token punctuation">.</span>923965       1 conntrack<span class="token punctuation">.</span>go:100<span class="token punctuation">]</span> <span class="token function">Set</span> sysctl <span class="token string">'net/netfilter/nf_conntrack_max'</span> to 131072
I0517 00:55:10<span class="token punctuation">.</span>924001       1 conntrack<span class="token punctuation">.</span>go:52<span class="token punctuation">]</span> Setting nf_conntrack_max to 131072
I0517 00:55:10<span class="token punctuation">.</span>924258       1 conntrack<span class="token punctuation">.</span>go:83<span class="token punctuation">]</span> Setting conntrack hashsize to 32768
I0517 00:55:10<span class="token punctuation">.</span>927041       1 conntrack<span class="token punctuation">.</span>go:100<span class="token punctuation">]</span> <span class="token function">Set</span> sysctl <span class="token string">'net/netfilter/nf_conntrack_tcp_timeout_established'</span> to 86400
I0517 00:55:10<span class="token punctuation">.</span>927086       1 conntrack<span class="token punctuation">.</span>go:100<span class="token punctuation">]</span> <span class="token function">Set</span> sysctl <span class="token string">'net/netfilter/nf_conntrack_tcp_timeout_close_wait'</span> to 3600
I0517 00:55:10<span class="token punctuation">.</span>927540       1 config<span class="token punctuation">.</span>go:315<span class="token punctuation">]</span> Starting service config controller
I0517 00:55:10<span class="token punctuation">.</span>927556       1 shared_informer<span class="token punctuation">.</span>go:223<span class="token punctuation">]</span> Waiting <span class="token keyword">for</span> caches to sync <span class="token keyword">for</span> service config
I0517 00:55:10<span class="token punctuation">.</span>927576       1 config<span class="token punctuation">.</span>go:133<span class="token punctuation">]</span> Starting endpoints config controller
I0517 00:55:10<span class="token punctuation">.</span>927594       1 shared_informer<span class="token punctuation">.</span>go:223<span class="token punctuation">]</span> Waiting <span class="token keyword">for</span> caches to sync <span class="token keyword">for</span> endpoints config
I0517 00:55:11<span class="token punctuation">.</span>027749       1 shared_informer<span class="token punctuation">.</span>go:230<span class="token punctuation">]</span> Caches are synced <span class="token keyword">for</span> service config
I0517 00:55:11<span class="token punctuation">.</span>027858       1 shared_informer<span class="token punctuation">.</span>go:230<span class="token punctuation">]</span> Caches are synced <span class="token keyword">for</span> endpoints config
</code></pre> 
  <h2>6.5 重新启动kube-proxy</h2> 
  <blockquote> 
   <p>删除kube-proxy-xxx的所有pod,让它重新拉取新的kube-proxy-xxx的pod</p> 
  </blockquote> 
  <pre><code class="prism language-powershell"><span class="token namespace">[root@k8s-master01 ~]</span><span class="token comment"># kubectl delete pod kube-proxy-69mv6 -n kube-system</span>
pod <span class="token string">"kube-proxy-69mv6"</span> deleted
<span class="token namespace">[root@k8s-master01 ~]</span><span class="token comment"># kubectl delete pod kube-proxy-jpc6c -n kube-system</span>
pod <span class="token string">"kube-proxy-jpc6c"</span> deleted
<span class="token namespace">[root@k8s-master01 ~]</span><span class="token comment"># kubectl delete pod kube-proxy-kq65l -n kube-system</span>
pod <span class="token string">"kube-proxy-kq65l"</span> deleted
<span class="token namespace">[root@k8s-master01 ~]</span><span class="token comment"># kubectl delete pod kube-proxy-lmphf -n kube-system</span>
pod <span class="token string">"kube-proxy-lmphf"</span> deleted
</code></pre> 
  <pre><code class="prism language-powershell"><span class="token namespace">[root@k8s-master01 ~]</span><span class="token comment"># kubectl get pods -n kube-system |grep kube-proxy</span>
kube-proxy-2mk2b                           1/1     Running   0          2m23s
kube-proxy-5bj87                           1/1     Running   0          30s
kube-proxy-7qq9l                           1/1     Running   0          52s
kube-proxy-tjtqf                           1/1     Running   0          80s
</code></pre> 
  <pre><code class="prism language-powershell">随意查看其中1个或3个kube-proxy-xxx的pod<span class="token punctuation">,</span>验证是否为IPVS方式了
<span class="token namespace">[root@k8s-master01 ~]</span><span class="token comment"># kubectl logs kube-proxy-tjtqf -n kube-system</span>
I0517 02:32:26<span class="token punctuation">.</span>557696       1 node<span class="token punctuation">.</span>go:136<span class="token punctuation">]</span> Successfully retrieved node IP: 192<span class="token punctuation">.</span>168<span class="token punctuation">.</span>122<span class="token punctuation">.</span>32
I0517 02:32:26<span class="token punctuation">.</span>557745       1 server_others<span class="token punctuation">.</span>go:259<span class="token punctuation">]</span> <span class="token keyword">Using</span> ipvs Proxier<span class="token punctuation">.</span>
W0517 02:32:26<span class="token punctuation">.</span>557912       1 proxier<span class="token punctuation">.</span>go:429<span class="token punctuation">]</span> IPVS scheduler not specified<span class="token punctuation">,</span> use rr by default
I0517 02:32:26<span class="token punctuation">.</span>560008       1 server<span class="token punctuation">.</span>go:583<span class="token punctuation">]</span> Version: v1<span class="token punctuation">.</span>18<span class="token punctuation">.</span>2
I0517 02:32:26<span class="token punctuation">.</span>560428       1 conntrack<span class="token punctuation">.</span>go:52<span class="token punctuation">]</span> Setting nf_conntrack_max to 131072
I0517 02:32:26<span class="token punctuation">.</span>561094       1 config<span class="token punctuation">.</span>go:315<span class="token punctuation">]</span> Starting service config controller
I0517 02:32:26<span class="token punctuation">.</span>562251       1 shared_informer<span class="token punctuation">.</span>go:223<span class="token punctuation">]</span> Waiting <span class="token keyword">for</span> caches to sync <span class="token keyword">for</span> service config
I0517 02:32:26<span class="token punctuation">.</span>561579       1 config<span class="token punctuation">.</span>go:133<span class="token punctuation">]</span> Starting endpoints config controller
I0517 02:32:26<span class="token punctuation">.</span>562271       1 shared_informer<span class="token punctuation">.</span>go:223<span class="token punctuation">]</span> Waiting <span class="token keyword">for</span> caches to sync <span class="token keyword">for</span> endpoints config
I0517 02:32:26<span class="token punctuation">.</span>662541       1 shared_informer<span class="token punctuation">.</span>go:230<span class="token punctuation">]</span> Caches are synced <span class="token keyword">for</span> service config
I0517 02:32:26<span class="token punctuation">.</span>662566       1 shared_informer<span class="token punctuation">.</span>go:230<span class="token punctuation">]</span> Caches are synced <span class="token keyword">for</span> endpoints config
</code></pre> 
 </div> 
</div>
                            </div>
                        </div>
                    </div>
                    <!--PC和WAP自适应版-->
                    <div id="SOHUCS" sid="1639316118835355648"></div>
                    <script type="text/javascript" src="/views/front/js/chanyan.js"></script>
                    <!-- 文章页-底部 动态广告位 -->
                    <div class="youdao-fixed-ad" id="detail_ad_bottom"></div>
                </div>
                <div class="col-md-3">
                    <div class="row" id="ad">
                        <!-- 文章页-右侧1 动态广告位 -->
                        <div id="right-1" class="col-lg-12 col-md-12 col-sm-4 col-xs-4 ad">
                            <div class="youdao-fixed-ad" id="detail_ad_1"> </div>
                        </div>
                        <!-- 文章页-右侧2 动态广告位 -->
                        <div id="right-2" class="col-lg-12 col-md-12 col-sm-4 col-xs-4 ad">
                            <div class="youdao-fixed-ad" id="detail_ad_2"></div>
                        </div>
                        <!-- 文章页-右侧3 动态广告位 -->
                        <div id="right-3" class="col-lg-12 col-md-12 col-sm-4 col-xs-4 ad">
                            <div class="youdao-fixed-ad" id="detail_ad_3"></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="container">
        <h4 class="pt20 mb15 mt0 border-top">你可能感兴趣的:(k8s,kubernetes)</h4>
        <div id="paradigm-article-related">
            <div class="recommend-post mb30">
                <ul class="widget-links">
                    <li><a href="/article/1835448111909138432.htm"
                           title="react-intl——react国际化使用方案" target="_blank">react-intl——react国际化使用方案</a>
                        <span class="text-muted">苹果酱0567</span>
<a class="tag" taget="_blank" href="/search/%E9%9D%A2%E8%AF%95%E9%A2%98%E6%B1%87%E6%80%BB%E4%B8%8E%E8%A7%A3%E6%9E%90/1.htm">面试题汇总与解析</a><a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/%E5%BC%80%E5%8F%91%E8%AF%AD%E8%A8%80/1.htm">开发语言</a><a class="tag" taget="_blank" href="/search/%E4%B8%AD%E9%97%B4%E4%BB%B6/1.htm">中间件</a><a class="tag" taget="_blank" href="/search/spring/1.htm">spring</a><a class="tag" taget="_blank" href="/search/boot/1.htm">boot</a><a class="tag" taget="_blank" href="/search/%E5%90%8E%E7%AB%AF/1.htm">后端</a>
                        <div>国际化介绍i18n:internationalization国家化简称,首字母+首尾字母间隔的字母个数+尾字母,类似的还有k8s(Kubernetes)React-intl是React中最受欢迎的库。使用步骤安装#usenpmnpminstallreact-intl-D#useyarn项目入口文件配置//index.tsximportReactfrom"react";importReactDOMf</div>
                    </li>
                    <li><a href="/article/1835379662918873088.htm"
                           title="【从问题中去学习k8s】k8s中的常见面试题(夯实理论基础)(二十八)" target="_blank">【从问题中去学习k8s】k8s中的常见面试题(夯实理论基础)(二十八)</a>
                        <span class="text-muted">向往风的男子</span>
<a class="tag" taget="_blank" href="/search/k8s/1.htm">k8s</a><a class="tag" taget="_blank" href="/search/%E5%AD%A6%E4%B9%A0/1.htm">学习</a><a class="tag" taget="_blank" href="/search/kubernetes/1.htm">kubernetes</a><a class="tag" taget="_blank" href="/search/%E5%AE%B9%E5%99%A8/1.htm">容器</a>
                        <div>本站以分享各种运维经验和运维所需要的技能为主《python零基础入门》:python零基础入门学习《python运维脚本》:python运维脚本实践《shell》:shell学习《terraform》持续更新中:terraform_Aws学习零基础入门到最佳实战《k8》从问题中去学习k8s《docker学习》暂未更新《ceph学习》ceph日常问题解决分享《日志收集》ELK+各种中间件《运维日常》</div>
                    </li>
                    <li><a href="/article/1835375621996376064.htm"
                           title="Kubernetes数据持久化" target="_blank">Kubernetes数据持久化</a>
                        <span class="text-muted">看清所苡看轻</span>
<a class="tag" taget="_blank" href="/search/kubernetes%28k8s%29/1.htm">kubernetes(k8s)</a><a class="tag" taget="_blank" href="/search/emptyDir/1.htm">emptyDir</a><a class="tag" taget="_blank" href="/search/HostPath/1.htm">HostPath</a><a class="tag" taget="_blank" href="/search/pv/1.htm">pv</a><a class="tag" taget="_blank" href="/search/pvc/1.htm">pvc</a><a class="tag" taget="_blank" href="/search/kubernetes/1.htm">kubernetes</a>
                        <div>在k8s中,Volume(数据卷)存在明确的生命周期(与包含该数据卷的容器组(pod)相同)。因此Volume的生命周期比同一容器组(pod)中任意容器的生命周期要更长,不管容器重启了多少次,数据都被保留下来。当然,如果pod不存在了,数据卷自然退出了。此时,根据pod所使用的数据卷类型不同,数据可能随着数据卷的退出而删除,也可能被真正持久化,并在下次容器组重启时仍然可以使用。从根本上来说,一个数</div>
                    </li>
                    <li><a href="/article/1835361001260806144.htm"
                           title="Kubernetes部署MySQL数据持久化" target="_blank">Kubernetes部署MySQL数据持久化</a>
                        <span class="text-muted">沫殇-MS</span>
<a class="tag" taget="_blank" href="/search/Kubernetes/1.htm">Kubernetes</a><a class="tag" taget="_blank" href="/search/MySQL%E6%95%B0%E6%8D%AE%E5%BA%93/1.htm">MySQL数据库</a><a class="tag" taget="_blank" href="/search/kubernetes/1.htm">kubernetes</a><a class="tag" taget="_blank" href="/search/mysql/1.htm">mysql</a><a class="tag" taget="_blank" href="/search/%E5%AE%B9%E5%99%A8/1.htm">容器</a>
                        <div>一、安装配置NFS服务端1、安装nfs-kernel-server:sudoapt-yinstallnfs-kernel-server2、服务端创建共享目录#列出所有可用块设备的信息lsblk#格式化磁盘sudomkfs-text4/dev/sdb#创建一个目录:sudomkdir-p/data/nfs/mysql#更改目录权限:sudochown-Rnobody:nogroup/data/nfs</div>
                    </li>
                    <li><a href="/article/1835354574077128704.htm"
                           title="Kubernetes的3种数据持久化方式" target="_blank">Kubernetes的3种数据持久化方式</a>
                        <span class="text-muted">Seal^_^</span>
<a class="tag" taget="_blank" href="/search/%E3%80%90%E4%BA%91%E5%8E%9F%E7%94%9F%E3%80%91%E5%AE%B9%E5%99%A8%E5%8C%96%E4%B8%8E%E7%BC%96%E6%8E%92%E6%8A%80%E6%9C%AF/1.htm">【云原生】容器化与编排技术</a><a class="tag" taget="_blank" href="/search/%E6%8C%81%E7%BB%AD%E9%9B%86%E6%88%90/1.htm">持续集成</a><a class="tag" taget="_blank" href="/search/%23/1.htm">#</a><a class="tag" taget="_blank" href="/search/Kubernetes/1.htm">Kubernetes</a><a class="tag" taget="_blank" href="/search/kubernetes/1.htm">kubernetes</a><a class="tag" taget="_blank" href="/search/%E5%AE%B9%E5%99%A8/1.htm">容器</a><a class="tag" taget="_blank" href="/search/%E4%BA%91%E5%8E%9F%E7%94%9F/1.htm">云原生</a><a class="tag" taget="_blank" href="/search/EmptyDir/1.htm">EmptyDir</a><a class="tag" taget="_blank" href="/search/%E9%9D%A2%E8%AF%95/1.htm">面试</a><a class="tag" taget="_blank" href="/search/HostPath/1.htm">HostPath</a>
                        <div>Kubernetes的3种数据持久化方式1.EmptyDir2.HostPath3.PersistentVolume(PV)TheBegin点点关注,收藏不迷路Kubernetes提供了几种数据持久化方式,以满足不同场景的需求:1.EmptyDir用途:临时数据存储,Pod内容器间共享。特点:生命周期与Pod相同,Pod删除时数据也删除。2.HostPath用途:访问宿主机特定文件或目录。特点:增</div>
                    </li>
                    <li><a href="/article/1835353689854930944.htm"
                           title="【Kubernetes】常见面试题汇总(十一)" target="_blank">【Kubernetes】常见面试题汇总(十一)</a>
                        <span class="text-muted">summer.335</span>
<a class="tag" taget="_blank" href="/search/Kubernetes/1.htm">Kubernetes</a><a class="tag" taget="_blank" href="/search/kubernetes/1.htm">kubernetes</a><a class="tag" taget="_blank" href="/search/%E5%AE%B9%E5%99%A8/1.htm">容器</a><a class="tag" taget="_blank" href="/search/%E4%BA%91%E5%8E%9F%E7%94%9F/1.htm">云原生</a>
                        <div>目录33.简述Kubernetes外部如何访问集群内的服务?34.简述Kubernetesingress?35.简述Kubernetes镜像的下载策略?33.简述Kubernetes外部如何访问集群内的服务?(1)对于Kubernetes,集群外的客户端默认情况,无法通过Pod的IP地址或者Service的虚拟IP地址:虚拟端口号进行访问。(2)通常可以通过以下方式进行访问Kubernetes集群</div>
                    </li>
                    <li><a href="/article/1835351925957160960.htm"
                           title="k8s中Service暴露的种类以及用法" target="_blank">k8s中Service暴露的种类以及用法</a>
                        <span class="text-muted">听说唐僧不吃肉</span>
<a class="tag" taget="_blank" href="/search/K8S/1.htm">K8S</a><a class="tag" taget="_blank" href="/search/kubernetes/1.htm">kubernetes</a><a class="tag" taget="_blank" href="/search/%E5%AE%B9%E5%99%A8/1.htm">容器</a><a class="tag" taget="_blank" href="/search/%E4%BA%91%E5%8E%9F%E7%94%9F/1.htm">云原生</a>
                        <div>一、说明在Kubernetes中,有几种不同的方式可以将服务(Service)暴露给外部流量。这些方式通过定义服务的spec.type字段来确定。二、详解1.ClusterIP定义:默认类型,服务只能在集群内部访问。作用:通过集群内部IP地址暴露服务。示例:spec:type:ClusterIPports:-port:80targetPo</div>
                    </li>
                    <li><a href="/article/1835349023540736000.htm"
                           title="二十四、k8s 资源管理" target="_blank">二十四、k8s 资源管理</a>
                        <span class="text-muted">繁华依在</span>
<a class="tag" taget="_blank" href="/search/k8s/1.htm">k8s</a><a class="tag" taget="_blank" href="/search/kubernetes/1.htm">kubernetes</a><a class="tag" taget="_blank" href="/search/%E5%AE%B9%E5%99%A8/1.htm">容器</a><a class="tag" taget="_blank" href="/search/%E4%BA%91%E5%8E%9F%E7%94%9F/1.htm">云原生</a>
                        <div>目录一、资源配置范围管理LimitRange介绍1、LimitRange可以做什么:2、资源限制和请求的约束3、创建LimitsRange对象4、示例:创建一个pod5、测试用例测试1:测试2:测试3:二、资源服务质量管理(RequestsQos)1、Qos级别分类:1.1、Guaranteed:1.2、BestEffort:1.3、Burstable:2、Qos的工作特点3、示例三、资源配额管理</div>
                    </li>
                    <li><a href="/article/1835347257772306432.htm"
                           title="Kubernetes 自定义控制器开发" target="_blank">Kubernetes 自定义控制器开发</a>
                        <span class="text-muted">IT回忆录</span>
<a class="tag" taget="_blank" href="/search/Kubenetes/1.htm">Kubenetes</a><a class="tag" taget="_blank" href="/search/kubernetes/1.htm">kubernetes</a>
                        <div>目录前言一、CRD二、创建数据库表(Mysql)二、控制器开发1.使用kubernetes的examplecontroller模板2.在controller.go中新增数据表监听方法3.修改tools工具生成资源对象结构体定义这里记录开发k8s控制器的一般方式,controller开发主要使用k8s提供的client-go库进行。前言Controller监听集群内部资源对象的变化,编辑资源对象(增</div>
                    </li>
                    <li><a href="/article/1835344356878413824.htm"
                           title="用kubedam搭建的k8s证书过期处理方法" target="_blank">用kubedam搭建的k8s证书过期处理方法</a>
                        <span class="text-muted">我滴鬼鬼呀wks</span>
<a class="tag" taget="_blank" href="/search/k8s/1.htm">k8s</a><a class="tag" taget="_blank" href="/search/1024%E7%A8%8B%E5%BA%8F%E5%91%98%E8%8A%82/1.htm">1024程序员节</a>
                        <div>kubeadm部署的k8s证书过期1、查看证书过期时间kubeadmalphacertscheck-expiration若证书已经过期无法试用kubectl命令建议修改服务器时间到未过期的时间段2、配置kube-controller-manager.yaml文件cat/etc/kubernetes/manifests/kube-controller-manager.yamlapiVersion:v</div>
                    </li>
                    <li><a href="/article/1835340955637608448.htm"
                           title="k8s证书过期问题处理" target="_blank">k8s证书过期问题处理</a>
                        <span class="text-muted">olina_qin</span>
<a class="tag" taget="_blank" href="/search/kubernetes/1.htm">kubernetes</a><a class="tag" taget="_blank" href="/search/%E5%AE%B9%E5%99%A8/1.htm">容器</a><a class="tag" taget="_blank" href="/search/%E4%BA%91%E5%8E%9F%E7%94%9F/1.htm">云原生</a>
                        <div>k8s证书过期问题处理opensslx509-in/etc/kubernetes/pki/apiserver.crt-noout-dateskubeadmcertsrenewallsystemctlrestartkubeleopensslx509-in/etc/kubernetes/pki/apiserver.crt-noout-text|grep"NotAfter"cp/etc/kubernet</div>
                    </li>
                    <li><a href="/article/1835337301350248448.htm"
                           title="Kubernetes Ingress 控制器(Nginx)安装与使用教程" target="_blank">Kubernetes Ingress 控制器(Nginx)安装与使用教程</a>
                        <span class="text-muted">农优影</span>

                        <div>KubernetesIngress控制器(Nginx)安装与使用教程kubernetes-ingressNGINXandNGINXPlusIngressControllersforKubernetes项目地址:https://gitcode.com/gh_mirrors/ku/kubernetes-ingress1.项目目录结构及介绍在nginxinc/kubernetes-ingress仓库中,</div>
                    </li>
                    <li><a href="/article/1835331377520799744.htm"
                           title="【K8s】专题十一:Kubernetes 集群证书过期处理方法" target="_blank">【K8s】专题十一:Kubernetes 集群证书过期处理方法</a>
                        <span class="text-muted">行者Sun1989</span>
<a class="tag" taget="_blank" href="/search/Kubernetes/1.htm">Kubernetes</a><a class="tag" taget="_blank" href="/search/kubernetes/1.htm">kubernetes</a><a class="tag" taget="_blank" href="/search/%E4%BA%91%E5%8E%9F%E7%94%9F/1.htm">云原生</a><a class="tag" taget="_blank" href="/search/%E5%AE%B9%E5%99%A8/1.htm">容器</a>
                        <div>本文内容均来自个人笔记并重新梳理,如有错误欢迎指正!如果对您有帮助,烦请点赞、关注、转发、订阅专栏!专栏订阅入口Linux专栏|Docker专栏|Kubernetes专栏往期精彩文章【Docker】(全网首发)KylinV10下MySQL容器内存占用异常的解决方法【Docker】(全网首发)KylinV10下MySQL容器内存占用异常的解决方法(续)【Docker】MySQL源码构建Docker镜</div>
                    </li>
                    <li><a href="/article/1835269935358636032.htm"
                           title="Docker学习十一:Kubernetes概述" target="_blank">Docker学习十一:Kubernetes概述</a>
                        <span class="text-muted">爱打羽球的程序猿</span>
<a class="tag" taget="_blank" href="/search/Docker%E5%AD%A6%E4%B9%A0%E7%B3%BB%E5%88%97/1.htm">Docker学习系列</a><a class="tag" taget="_blank" href="/search/docker/1.htm">docker</a><a class="tag" taget="_blank" href="/search/kubernetes/1.htm">kubernetes</a><a class="tag" taget="_blank" href="/search/%E5%AD%A6%E4%B9%A0/1.htm">学习</a>
                        <div>一、Kubernetes简介2006年,Google提出了云计算的概念,当时的云计算领域还是以虚拟机为代表的云平台。2013年,Docker横空出世,Docker提出了镜像、仓库等核心概念,规范了服务的交付标准,使得复杂服务的落地变得更加简单,之后Docker又定义了OCI标准,Docker在容器领域称为事实的标准。但是,Docker诞生只是帮助定义了开发和交付标准,如果想要在生产环境中大批量的使</div>
                    </li>
                    <li><a href="/article/1835269304761806848.htm"
                           title="Cloud Native Weekly | 华为云抢先发布Redis5.0,红帽宣布收购混合云提供商" target="_blank">Cloud Native Weekly | 华为云抢先发布Redis5.0,红帽宣布收购混合云提供商</a>
                        <span class="text-muted">weixin_34302561</span>
<a class="tag" taget="_blank" href="/search/%E6%95%B0%E6%8D%AE%E5%BA%93/1.htm">数据库</a><a class="tag" taget="_blank" href="/search/devops/1.htm">devops</a><a class="tag" taget="_blank" href="/search/%E5%A4%A7%E6%95%B0%E6%8D%AE/1.htm">大数据</a>
                        <div>1——华为云抢先发布Redis5.02——DigitalOceanK8s服务正式上线3——红帽宣布收购混合云提供商NooBaa4——微软发布多项AzureKubernetes服务更新1华为云抢先发布Redis5.012月17日,华为云在DCS2.0的基础上,快人一步,抢先推出了新的Redis5.0产品,这是一个崭新的突破。目前国内在缓存领域的发展普遍停留在Redis4.0阶段,华为云率先发布了Re</div>
                    </li>
                    <li><a href="/article/1835262244313722880.htm"
                           title="SpringBoot整合ES搜索引擎 实现网站热搜词及热度计算" target="_blank">SpringBoot整合ES搜索引擎 实现网站热搜词及热度计算</a>
                        <span class="text-muted">码踏云端</span>
<a class="tag" taget="_blank" href="/search/springboot/1.htm">springboot</a><a class="tag" taget="_blank" href="/search/Elasticsearch/1.htm">Elasticsearch</a><a class="tag" taget="_blank" href="/search/spring/1.htm">spring</a><a class="tag" taget="_blank" href="/search/boot/1.htm">boot</a><a class="tag" taget="_blank" href="/search/elasticsearch/1.htm">elasticsearch</a><a class="tag" taget="_blank" href="/search/%E5%90%8E%E7%AB%AF/1.htm">后端</a><a class="tag" taget="_blank" href="/search/%E7%83%AD%E6%90%9C%E8%AF%8D/1.htm">热搜词</a><a class="tag" taget="_blank" href="/search/%E7%83%AD%E5%BA%A6%E8%AE%A1%E7%AE%97/1.htm">热度计算</a><a class="tag" taget="_blank" href="/search/java/1.htm">java</a>
                        <div>博主简介:历代文学网(PC端可以访问:https://literature.sinhy.com/#/literature?__c=1000,移动端可微信小程序搜索“历代文学”)总架构师,15年工作经验,精通Java编程,高并发设计,Springboot和微服务,熟悉Linux,ESXI虚拟化以及云原生Docker和K8s,热衷于探索科技的边界,并将理论知识转化为实际应用。保持对新技术的好奇心,乐于</div>
                    </li>
                    <li><a href="/article/1835209173944594432.htm"
                           title="(k8s)Kubernetes 从0到1容器编排之旅" target="_blank">(k8s)Kubernetes 从0到1容器编排之旅</a>
                        <span class="text-muted">道不贱卖,法不轻传</span>
<a class="tag" taget="_blank" href="/search/kubernets/1.htm">kubernets</a><a class="tag" taget="_blank" href="/search/kubernetes/1.htm">kubernetes</a><a class="tag" taget="_blank" href="/search/%E5%AE%B9%E5%99%A8/1.htm">容器</a><a class="tag" taget="_blank" href="/search/%E4%BA%91%E5%8E%9F%E7%94%9F/1.htm">云原生</a>
                        <div>一、引言在当今数字化的浪潮中,Kubernetes如同一艘强大的航船,引领着容器化应用的部署与管理。它以其卓越的灵活性、可扩展性和可靠性,成为众多企业和开发者的首选。然而,要真正发挥Kubernetes的强大威力,仅仅掌握基本操作是远远不够的。本文将带你深入探索Kubernetes使用过程中的奇技妙法,为你开启一段优雅的容器编排之旅。二、高级资源管理之精妙艺术1.资源配额与限制:雕琢资源之美•Ku</div>
                    </li>
                    <li><a href="/article/1835133243985326080.htm"
                           title="ETCD 六 etcd总体架构" target="_blank">ETCD 六 etcd总体架构</a>
                        <span class="text-muted">wanghaichao1234</span>
<a class="tag" taget="_blank" href="/search/etcd/1.htm">etcd</a><a class="tag" taget="_blank" href="/search/etcd/1.htm">etcd</a><a class="tag" taget="_blank" href="/search/%E6%9E%B6%E6%9E%84/1.htm">架构</a><a class="tag" taget="_blank" href="/search/%E6%95%B0%E6%8D%AE%E5%BA%93/1.htm">数据库</a>
                        <div>etcd源码结构etcd项目代码的目录结构:包名用途apiprotobuf定义client/v3客户端sdkcontribraftexample实现etcdctl命令行客户端实现,用于网路的操作etcdutl命令行管理工具,直接操作etcd数据文件。hack基准测试、测试集群、k8s部署、分支管理、证书等pkg实用程序包的集合raftraft实现server.auth角色身份验证server.em</div>
                    </li>
                    <li><a href="/article/1835061888858288128.htm"
                           title="【K8S】kubernetes集群架构与组件" target="_blank">【K8S】kubernetes集群架构与组件</a>
                        <span class="text-muted">奇奇怪怪^</span>
<a class="tag" taget="_blank" href="/search/%E4%BA%91/1.htm">云</a><a class="tag" taget="_blank" href="/search/Linux/1.htm">Linux</a><a class="tag" taget="_blank" href="/search/IT/1.htm">IT</a><a class="tag" taget="_blank" href="/search/%E8%BF%90%E7%BB%B4/1.htm">运维</a><a class="tag" taget="_blank" href="/search/%E6%9C%8D%E5%8A%A1%E5%99%A8/1.htm">服务器</a><a class="tag" taget="_blank" href="/search/linux/1.htm">linux</a>
                        <div>文章目录【K8S】kubernetes集群架构与组件kubernetes组件**master组件**node组件整体流程POD终止过程【K8S】kubernetes集群架构与组件kubernetes组件K8S是属于主从设备模型(Master-slave架构),即有Master节点负责集群的调度、管理和运维,Slave节点是集群中的运算工作负载节点在K8S中,主节点一般被称为Master节点,而从节</div>
                    </li>
                    <li><a href="/article/1835058988631289856.htm"
                           title="K8S学习笔记02——K8S组件" target="_blank">K8S学习笔记02——K8S组件</a>
                        <span class="text-muted">沉淅尘</span>
<a class="tag" taget="_blank" href="/search/%23/1.htm">#</a><a class="tag" taget="_blank" href="/search/Docker/1.htm">Docker</a><a class="tag" taget="_blank" href="/search/%23/1.htm">#</a><a class="tag" taget="_blank" href="/search/K8S/1.htm">K8S</a><a class="tag" taget="_blank" href="/search/kubernetes/1.htm">kubernetes</a>
                        <div>Kubernetes组件一、控制平面组件(ControlPlaneComponents)(1)kube-apiserver(2)etcd(3)kube-scheduler(4)kube-controller-manager(5)cloud-controller-manager二、Node组件1.kubelet2.kube-proxy3.容器运行时(ContainerRuntime)三、插件(Add</div>
                    </li>
                    <li><a href="/article/1835054063679533056.htm"
                           title="Kubernetes——组件" target="_blank">Kubernetes——组件</a>
                        <span class="text-muted">窒息う</span>
<a class="tag" taget="_blank" href="/search/Kubernetes/1.htm">Kubernetes</a><a class="tag" taget="_blank" href="/search/kubernetes/1.htm">kubernetes</a><a class="tag" taget="_blank" href="/search/%E5%AE%B9%E5%99%A8/1.htm">容器</a>
                        <div>文章目录K8S的优势核心架构角色与功能集群图例K8S的优势能管理大量跨主机容器快速部署应用快速扩展应用无缝对接新的应用节省资源,优化硬件资源的使用核心架构master(管理节点)node(计算节点)images(镜像节点)角色与功能Master功能提供集群的控制对集群进行全局决策检测和响应集群事件Master节点核心组件APIServer是整个系统的对外接口,提供客户端和其他组件调用后端元数据存储</div>
                    </li>
                    <li><a href="/article/1835046751275413504.htm"
                           title="Kubernetes组件" target="_blank">Kubernetes组件</a>
                        <span class="text-muted">汉只只</span>
<a class="tag" taget="_blank" href="/search/%E7%BD%91%E7%BB%9C/1.htm">网络</a><a class="tag" taget="_blank" href="/search/docker/1.htm">docker</a><a class="tag" taget="_blank" href="/search/%E5%A4%A7%E6%95%B0%E6%8D%AE/1.htm">大数据</a><a class="tag" taget="_blank" href="/search/%E5%88%86%E5%B8%83%E5%BC%8F/1.htm">分布式</a><a class="tag" taget="_blank" href="/search/hadoop/1.htm">hadoop</a>
                        <div>Kubernetes核心组件Kubernetes定义了一组构建块,它们可以共同提供部署、维护和扩展应用程序的机制。组成Kubernetes的组件设计为松耦合和可扩展的,这样可以满足多种不同的工作负载。可扩展性在很大程度上由KubernetesAPI提供——它被作为扩展的内部组件以及Kubernetes上运行的容器等使用。Kubernetes主要由以下几个核心组件组成:etcd保存了整个集群的状态;</div>
                    </li>
                    <li><a href="/article/1835034781197365248.htm"
                           title="【Linux 从基础到进阶】Kubernetes 集群搭建与管理" target="_blank">【Linux 从基础到进阶】Kubernetes 集群搭建与管理</a>
                        <span class="text-muted">爱技术的小伙子</span>
<a class="tag" taget="_blank" href="/search/Linux%E4%BB%8E%E5%9F%BA%E7%A1%80%E5%88%B0%E8%BF%9B%E9%98%B6/1.htm">Linux从基础到进阶</a><a class="tag" taget="_blank" href="/search/linux/1.htm">linux</a><a class="tag" taget="_blank" href="/search/kubernetes/1.htm">kubernetes</a><a class="tag" taget="_blank" href="/search/%E8%BF%90%E7%BB%B4/1.htm">运维</a>
                        <div>Kubernetes集群搭建与管理Kubernetes(简称K8s)是一个用于自动化部署、扩展和管理容器化应用程序的开源平台。它提供了容器编排功能,能够管理大量的容器实例,并支持应用的自动扩展、高可用性和自愈能力。本文将详细介绍如何在CentOS和Ubuntu系统上安装和配置Kubernetes集群,并讲解Kubernetes的基本概念和管理操作。1.Kubernetes基础概念在了解如何搭建Ku</div>
                    </li>
                    <li><a href="/article/1835027774545424384.htm"
                           title="k3s原理分析丨如何搞定k3s node注册失败问题" target="_blank">k3s原理分析丨如何搞定k3s node注册失败问题</a>
                        <span class="text-muted">k3s中文社区</span>

                        <div>前言面向边缘的轻量级K8S发行版k3s于去年2月底发布后,备受关注,在发布后的10个月时间里,GithubStar达11,000颗。于去年11月中旬已经GA。但正如你所知,没有一个产品是十全十美的,k3s在客户落地实践的过程中也暴露过一些不足。在k3s技术团队的专业技术支持下,许多问题得到了改善和解决。我们精选了一些在实际生产环境中的问题处理案例,分享给正在使用k3s的你。希望k3s技术团队的经验</div>
                    </li>
                    <li><a href="/article/1834999728476090368.htm"
                           title="【Kubernetes】常见面试题汇总(十三)" target="_blank">【Kubernetes】常见面试题汇总(十三)</a>
                        <span class="text-muted">summer.335</span>
<a class="tag" taget="_blank" href="/search/Kubernetes/1.htm">Kubernetes</a><a class="tag" taget="_blank" href="/search/kubernetes/1.htm">kubernetes</a><a class="tag" taget="_blank" href="/search/%E5%AE%B9%E5%99%A8/1.htm">容器</a><a class="tag" taget="_blank" href="/search/%E4%BA%91%E5%8E%9F%E7%94%9F/1.htm">云原生</a>
                        <div>目录39.简述KubernetesScheduler使用哪两种算法将Pod绑定到worker节点?40.简述Kuberneteskubelet的作用?41.简述Kuberneteskubelet监控Worker节点资源是使用什么组件来实现的?39.简述KubernetesScheduler使用哪两种算法将Pod绑定到worker节点?KubernetesScheduler根据如下两种调度算法将Po</div>
                    </li>
                    <li><a href="/article/1834931642712551424.htm"
                           title="K8S学习之PV&&PVC" target="_blank">K8S学习之PV&&PVC</a>
                        <span class="text-muted">david161</span>

                        <div>部署mysql之前我们需要先了解一个概念有状态服务。这是一种特殊的服务,简单的归纳下就是会产生需要持久化的数据,并且有很强的I/O需求,且重启需要依赖上次存储到磁盘的数据。如典型的mysql,kafka,zookeeper等等。在我们有比较优秀的商业存储的前提下,非常推荐使用有状态服务进行部署,计算和存储分离那是相当的爽的。在实际生产中如果没有这种存储,localPV也是不错的选择,当然local</div>
                    </li>
                    <li><a href="/article/1834893444238110720.htm"
                           title="Ansible自动化部署kubernetes集群" target="_blank">Ansible自动化部署kubernetes集群</a>
                        <span class="text-muted">theo.wu</span>
<a class="tag" taget="_blank" href="/search/kubernetes/1.htm">kubernetes</a><a class="tag" taget="_blank" href="/search/ansible/1.htm">ansible</a><a class="tag" taget="_blank" href="/search/%E8%87%AA%E5%8A%A8%E5%8C%96/1.htm">自动化</a>
                        <div>机器环境介绍1.1.机器信息介绍IPhostnameapplicationCPUMemory192.168.204.129k8s-master01etcd,kube-apiserver,kube-controller-manager,kube-scheduler,kubelet,kube-proxy,containerd2C4G192.168.204.130k8s-worker01etcd,kub</div>
                    </li>
                    <li><a href="/article/1834800037679427584.htm"
                           title="K8S - Volume - NFS 卷的简介和使用" target="_blank">K8S - Volume - NFS 卷的简介和使用</a>
                        <span class="text-muted">nvd11</span>
<a class="tag" taget="_blank" href="/search/K8S/1.htm">K8S</a><a class="tag" taget="_blank" href="/search/kubernetes/1.htm">kubernetes</a><a class="tag" taget="_blank" href="/search/%E5%AE%B9%E5%99%A8/1.htm">容器</a><a class="tag" taget="_blank" href="/search/%E4%BA%91%E5%8E%9F%E7%94%9F/1.htm">云原生</a>
                        <div>在之前的文章里已经介绍了K8S中两个简单卷类型hostpath和emptydirk8s-Volume简介和HostPath的使用K8S-Emptydir-取代ELK使用fluentd构建loggingsaidcar但是这两种卷都有同1个限制,就是依赖于k8snodes的空间如果某个servicepod中需要的volumn空间很大,这时我们就需要考虑网络磁盘方案,其中NAS类型的Volume是常用且</div>
                    </li>
                    <li><a href="/article/1834799785203298304.htm"
                           title="fluentd 简介,日志收集并导入BigQuery" target="_blank">fluentd 简介,日志收集并导入BigQuery</a>
                        <span class="text-muted">nvd11</span>
<a class="tag" taget="_blank" href="/search/Cloud/1.htm">Cloud</a><a class="tag" taget="_blank" href="/search/spring/1.htm">spring</a><a class="tag" taget="_blank" href="/search/Etl/1.htm">Etl</a><a class="tag" taget="_blank" href="/search/spring/1.htm">spring</a><a class="tag" taget="_blank" href="/search/boot/1.htm">boot</a>
                        <div>日志收集的工具有很多种例如Splunk,很多大公司都在使用,但是个人使用的话并不合适,主要是需要license的…钱是1个大问题另1个常见开源的解决方案是ELK,但是搭建和学习成本高,如果只是为了日志收集并不值。对于k8s方案,还有1个开源选择,就是fluentd,本文的主题。Fluentd的简介Fluentd是一个开源的数据收集器,旨在实现日志数据的统一收集、处理和转发。它支持多种数据源和数据格</div>
                    </li>
                    <li><a href="/article/1834787055985586176.htm"
                           title="K8S - Emptydir - 取代ELK 使用fluentd 构建logging saidcar" target="_blank">K8S - Emptydir - 取代ELK 使用fluentd 构建logging saidcar</a>
                        <span class="text-muted">nvd11</span>
<a class="tag" taget="_blank" href="/search/K8S/1.htm">K8S</a><a class="tag" taget="_blank" href="/search/kubernetes/1.htm">kubernetes</a>
                        <div>由于k8s的无状态service通常部署在多个POD中,实现多实例面向高并发。但是k8s本身并没有提供集中查询多个pod的日志的功能其中1个常见方案就是ELK.本文的方案是利用fluentdsidecar和emptydir把多个pod的日志导向到bigquery的table中。Emptydir的简介Kubernetes中的EmptyDir是一种用于容器之间共享临时存储的空目录卷类型。EmptyDi</div>
                    </li>
                                <li><a href="/article/101.htm"
                                       title="数据采集高并发的架构应用" target="_blank">数据采集高并发的架构应用</a>
                                    <span class="text-muted">3golden</span>
<a class="tag" taget="_blank" href="/search/.net/1.htm">.net</a>
                                    <div>问题的出发点: 
 
         最近公司为了发展需要,要扩大对用户的信息采集,每个用户的采集量估计约2W。如果用户量增加的话,将会大量照成采集量成3W倍的增长,但是又要满足日常业务需要,特别是指令要及时得到响应的频率次数远大于预期。 
      &n</div>
                                </li>
                                <li><a href="/article/228.htm"
                                       title="不停止 MySQL 服务增加从库的两种方式" target="_blank">不停止 MySQL 服务增加从库的两种方式</a>
                                    <span class="text-muted">brotherlamp</span>
<a class="tag" taget="_blank" href="/search/linux/1.htm">linux</a><a class="tag" taget="_blank" href="/search/linux%E8%A7%86%E9%A2%91/1.htm">linux视频</a><a class="tag" taget="_blank" href="/search/linux%E8%B5%84%E6%96%99/1.htm">linux资料</a><a class="tag" taget="_blank" href="/search/linux%E6%95%99%E7%A8%8B/1.htm">linux教程</a><a class="tag" taget="_blank" href="/search/linux%E8%87%AA%E5%AD%A6/1.htm">linux自学</a>
                                    <div>现在生产环境MySQL数据库是一主一从,由于业务量访问不断增大,故再增加一台从库。前提是不能影响线上业务使用,也就是说不能重启MySQL服务,为了避免出现其他情况,选择在网站访问量低峰期时间段操作。 
 一般在线增加从库有两种方式,一种是通过mysqldump备份主库,恢复到从库,mysqldump是逻辑备份,数据量大时,备份速度会很慢,锁表的时间也会很长。另一种是通过xtrabacku</div>
                                </li>
                                <li><a href="/article/355.htm"
                                       title="Quartz——SimpleTrigger触发器" target="_blank">Quartz——SimpleTrigger触发器</a>
                                    <span class="text-muted">eksliang</span>
<a class="tag" taget="_blank" href="/search/SimpleTrigger/1.htm">SimpleTrigger</a><a class="tag" taget="_blank" href="/search/TriggerUtils/1.htm">TriggerUtils</a><a class="tag" taget="_blank" href="/search/quartz/1.htm">quartz</a>
                                    <div>转载请出自出处:http://eksliang.iteye.com/blog/2208166 一.概述 
SimpleTrigger触发器,当且仅需触发一次或者以固定时间间隔周期触发执行; 
  二.SimpleTrigger的构造函数 
 
 SimpleTrigger(String name, String group):通过该构造函数指定Trigger所属组和名称; 
 Simpl</div>
                                </li>
                                <li><a href="/article/482.htm"
                                       title="Informatica应用(1)" target="_blank">Informatica应用(1)</a>
                                    <span class="text-muted">18289753290</span>
<a class="tag" taget="_blank" href="/search/sql/1.htm">sql</a><a class="tag" taget="_blank" href="/search/workflow/1.htm">workflow</a><a class="tag" taget="_blank" href="/search/lookup/1.htm">lookup</a><a class="tag" taget="_blank" href="/search/%E7%BB%84%E4%BB%B6/1.htm">组件</a><a class="tag" taget="_blank" href="/search/Informatica/1.htm">Informatica</a>
                                    <div>1.如果要在workflow中调用shell脚本有一个command组件,在里面设置shell的路径;调度wf可以右键出现schedule,现在用的是HP的tidal调度wf的执行。 
2.designer里面的router类似于SSIS中的broadcast(多播组件);Reset_Workflow_Var:参数重置 (比如说我这个参数初始是1在workflow跑得过程中变成了3我要在结束时还要</div>
                                </li>
                                <li><a href="/article/609.htm"
                                       title="python 获取图片验证码中文字" target="_blank">python 获取图片验证码中文字</a>
                                    <span class="text-muted">酷的飞上天空</span>
<a class="tag" taget="_blank" href="/search/python/1.htm">python</a>
                                    <div>根据现成的开源项目 http://code.google.com/p/pytesser/改写 
在window上用easy_install安装不上  看了下源码发现代码很少  于是就想自己改写一下 
  
添加支持网络图片的直接解析 
  
  
#coding:utf-8 
#import sys 
#reload(sys) 
#sys.s</div>
                                </li>
                                <li><a href="/article/736.htm"
                                       title="AJAX" target="_blank">AJAX</a>
                                    <span class="text-muted">永夜-极光</span>
<a class="tag" taget="_blank" href="/search/Ajax/1.htm">Ajax</a>
                                    <div>1.AJAX功能:动态更新页面,减少流量消耗,减轻服务器负担 
  
2.代码结构: 
   
<html>

<head>
<script type="text/javascript">
function loadXMLDoc()
{
.... AJAX script goes here ...
</div>
                                </li>
                                <li><a href="/article/863.htm"
                                       title="创业OR读研" target="_blank">创业OR读研</a>
                                    <span class="text-muted">随便小屋</span>
<a class="tag" taget="_blank" href="/search/%E5%88%9B%E4%B8%9A/1.htm">创业</a>
                                    <div>        现在研一,有种想创业的想法,不知道该不该去实施。因为对于的我情况这两者是矛盾的,可能就是鱼与熊掌不能兼得。 
       
        研一的生活刚刚过去两个月,我们学校主要的是</div>
                                </li>
                                <li><a href="/article/990.htm"
                                       title="需求做得好与坏直接关系着程序员生活质量" target="_blank">需求做得好与坏直接关系着程序员生活质量</a>
                                    <span class="text-muted">aijuans</span>
<a class="tag" taget="_blank" href="/search/IT+%E7%94%9F%E6%B4%BB/1.htm">IT 生活</a>
                                    <div>  
        这个故事还得从去年换工作的事情说起,由于自己不太喜欢第一家公司的环境我选择了换一份工作。去年九月份我入职现在的这家公司,专门从事金融业内软件的开发。十一月份我们整个项目组前往北京做现场开发,从此苦逼的日子开始了。 
       系统背景:五月份就有同事前往甲方了解需求一直到6月份,后续几个月也完</div>
                                </li>
                                <li><a href="/article/1117.htm"
                                       title="如何定义和区分高级软件开发工程师" target="_blank">如何定义和区分高级软件开发工程师</a>
                                    <span class="text-muted">aoyouzi</span>

                                    <div>在软件开发领域,高级开发工程师通常是指那些编写代码超过 3 年的人。这些人可能会被放到领导的位置,但经常会产生非常糟糕的结果。Matt Briggs 是一名高级开发工程师兼 Scrum 管理员。他认为,单纯使用年限来划分开发人员存在问题,两个同样具有 10 年开发经验的开发人员可能大不相同。近日,他发表了一篇博文,根据开发者所能发挥的作用划分软件开发工程师的成长阶段。 
  初</div>
                                </li>
                                <li><a href="/article/1244.htm"
                                       title="Servlet的请求与响应" target="_blank">Servlet的请求与响应</a>
                                    <span class="text-muted">百合不是茶</span>
<a class="tag" taget="_blank" href="/search/servlet/1.htm">servlet</a><a class="tag" taget="_blank" href="/search/get%E6%8F%90%E4%BA%A4/1.htm">get提交</a><a class="tag" taget="_blank" href="/search/java%E5%A4%84%E7%90%86post%E6%8F%90%E4%BA%A4/1.htm">java处理post提交</a>
                                    <div>  
Servlet是tomcat中的一个重要组成,也是负责客户端和服务端的中介 
  
  
1,Http的请求方式(get  ,post); 
  客户端的请求一般都会都是Servlet来接受的,在接收之前怎么来确定是那种方式提交的,以及如何反馈,Servlet中有相应的方法,  http的get方式 servlet就是都doGet(</div>
                                </li>
                                <li><a href="/article/1371.htm"
                                       title="web.xml配置详解之listener" target="_blank">web.xml配置详解之listener</a>
                                    <span class="text-muted">bijian1013</span>
<a class="tag" taget="_blank" href="/search/java/1.htm">java</a><a class="tag" taget="_blank" href="/search/web.xml/1.htm">web.xml</a><a class="tag" taget="_blank" href="/search/listener/1.htm">listener</a>
                                    <div>一.定义 
<listener>  
	<listen-class>com.myapp.MyListener</listen-class>  
</listener> 
  
二.作用        该元素用来注册一个监听器类。可以收到事件什么时候发生以及用什么作为响</div>
                                </li>
                                <li><a href="/article/1498.htm"
                                       title="Web页面性能优化(yahoo技术)" target="_blank">Web页面性能优化(yahoo技术)</a>
                                    <span class="text-muted">Bill_chen</span>
<a class="tag" taget="_blank" href="/search/JavaScript/1.htm">JavaScript</a><a class="tag" taget="_blank" href="/search/Ajax/1.htm">Ajax</a><a class="tag" taget="_blank" href="/search/Web/1.htm">Web</a><a class="tag" taget="_blank" href="/search/css/1.htm">css</a><a class="tag" taget="_blank" href="/search/Yahoo/1.htm">Yahoo</a>
                                    <div>1.尽可能的减少HTTP请求数 content 
2.使用CDN server 
3.添加Expires头(或者 Cache-control) server 
4.Gzip 组件 server 
5.把CSS样式放在页面的上方。 css 
6.将脚本放在底部(包括内联的) javascript 
7.避免在CSS中使用Expressions css 
8.将javascript和css独立成外部文</div>
                                </li>
                                <li><a href="/article/1625.htm"
                                       title="【MongoDB学习笔记八】MongoDB游标、分页查询、查询结果排序" target="_blank">【MongoDB学习笔记八】MongoDB游标、分页查询、查询结果排序</a>
                                    <span class="text-muted">bit1129</span>
<a class="tag" taget="_blank" href="/search/mongodb/1.htm">mongodb</a>
                                    <div>游标 
  
游标,简单的说就是一个查询结果的指针。游标作为数据库的一个对象,使用它是包括 
 
 声明 
 打开 
 循环抓去一定数目的文档直到结果集中的所有文档已经抓取完 
 关闭游标 
 
  
游标的基本用法,类似于JDBC的ResultSet(hasNext判断是否抓去完,next移动游标到下一条文档),在获取一个文档集时,可以提供一个类似JDBC的FetchSize</div>
                                </li>
                                <li><a href="/article/1752.htm"
                                       title="ORA-12514 TNS 监听程序当前无法识别连接描述符中请求服务 的解决方法" target="_blank">ORA-12514 TNS 监听程序当前无法识别连接描述符中请求服务 的解决方法</a>
                                    <span class="text-muted">白糖_</span>
<a class="tag" taget="_blank" href="/search/ORA-12514/1.htm">ORA-12514</a>
                                    <div> 今天通过Oracle SQL*Plus连接远端服务器的时候提示“监听程序当前无法识别连接描述符中请求服务”,遂在网上找到了解决方案: 
 ①打开Oracle服务器安装目录\NETWORK\ADMIN\listener.ora文件,你会看到如下信息: 
  
# listener.ora Network Configuration File: D:\database\Oracle\net</div>
                                </li>
                                <li><a href="/article/1879.htm"
                                       title="Eclipse 问题 A resource exists with a different case" target="_blank">Eclipse 问题 A resource exists with a different case</a>
                                    <span class="text-muted">bozch</span>
<a class="tag" taget="_blank" href="/search/eclipse/1.htm">eclipse</a>
                                    <div>在使用Eclipse进行开发的时候,出现了如下的问题: 
Description Resource Path Location TypeThe project was not built due to "A resource exists with a different case: '/SeenTaoImp_zhV2/bin/seentao'.&</div>
                                </li>
                                <li><a href="/article/2006.htm"
                                       title="编程之美-小飞的电梯调度算法" target="_blank">编程之美-小飞的电梯调度算法</a>
                                    <span class="text-muted">bylijinnan</span>
<a class="tag" taget="_blank" href="/search/%E7%BC%96%E7%A8%8B%E4%B9%8B%E7%BE%8E/1.htm">编程之美</a>
                                    <div>

public class AptElevator {

	/**
	 * 编程之美 小飞 电梯调度算法
	 * 在繁忙的时间,每次电梯从一层往上走时,我们只允许电梯停在其中的某一层。
	 * 所有乘客都从一楼上电梯,到达某层楼后,电梯听下来,所有乘客再从这里爬楼梯到自己的目的层。
	 * 在一楼时,每个乘客选择自己的目的层,电梯则自动计算出应停的楼层。
	 * 问:电梯停在哪</div>
                                </li>
                                <li><a href="/article/2133.htm"
                                       title="SQL注入相关概念" target="_blank">SQL注入相关概念</a>
                                    <span class="text-muted">chenbowen00</span>
<a class="tag" taget="_blank" href="/search/sql/1.htm">sql</a><a class="tag" taget="_blank" href="/search/Web/1.htm">Web</a><a class="tag" taget="_blank" href="/search/%E5%AE%89%E5%85%A8/1.htm">安全</a>
                                    <div>SQL Injection:就是通过把SQL命令插入到Web表单递交或输入域名或页面请求的查询字符串,最终达到欺骗服务器执行恶意的SQL命令。 
 
具体来说,它是利用现有应用程序,将(恶意)的SQL命令注入到后台数据库引擎执行的能力,它可以通过在Web表单中输入(恶意)SQL语句得到一个存在安全漏洞的网站上的数据库,而不是按照设计者意图去执行SQL语句。 
 
首先让我们了解什么时候可能发生SQ</div>
                                </li>
                                <li><a href="/article/2260.htm"
                                       title="[光与电]光子信号战防御原理" target="_blank">[光与电]光子信号战防御原理</a>
                                    <span class="text-muted">comsci</span>
<a class="tag" taget="_blank" href="/search/%E5%8E%9F%E7%90%86/1.htm">原理</a>
                                    <div> 
 
      无论是在战场上,还是在后方,敌人都有可能用光子信号对人体进行控制和攻击,那么采取什么样的防御方法,最简单,最有效呢? 
 
      我们这里有几个山寨的办法,可能有些作用,大家如果有兴趣可以去实验一下 
 
      根据光</div>
                                </li>
                                <li><a href="/article/2387.htm"
                                       title="oracle 11g新特性:Pending Statistics" target="_blank">oracle 11g新特性:Pending Statistics</a>
                                    <span class="text-muted">daizj</span>
<a class="tag" taget="_blank" href="/search/oracle/1.htm">oracle</a><a class="tag" taget="_blank" href="/search/dbms_stats/1.htm">dbms_stats</a>
                                    <div>oracle 11g新特性:Pending Statistics 转 
 
从11g开始,表与索引的统计信息收集完毕后,可以选择收集的统信息立即发布,也可以选择使新收集的统计信息处于pending状态,待确定处于pending状态的统计信息是安全的,再使处于pending状态的统计信息发布,这样就会避免一些因为收集统计信息立即发布而导致SQL执行计划走错的灾难。 
 
在 11g 之前的版本中,D</div>
                                </li>
                                <li><a href="/article/2514.htm"
                                       title="快速理解RequireJs" target="_blank">快速理解RequireJs</a>
                                    <span class="text-muted">dengkane</span>
<a class="tag" taget="_blank" href="/search/jquery/1.htm">jquery</a><a class="tag" taget="_blank" href="/search/requirejs/1.htm">requirejs</a>
                                    <div>RequireJs已经流行很久了,我们在项目中也打算使用它。它提供了以下功能: 
 
 声明不同js文件之间的依赖 
 可以按需、并行、延时载入js库 
 可以让我们的代码以模块化的方式组织 
 
初看起来并不复杂。 在html中引入requirejs 
在HTML中,添加这样的 <script> 标签: 
<script src="/path/to</div>
                                </li>
                                <li><a href="/article/2641.htm"
                                       title="C语言学习四流程控制if条件选择、for循环和强制类型转换" target="_blank">C语言学习四流程控制if条件选择、for循环和强制类型转换</a>
                                    <span class="text-muted">dcj3sjt126com</span>
<a class="tag" taget="_blank" href="/search/c/1.htm">c</a>
                                    <div># include <stdio.h>

int main(void)
{
	int i, j;

	scanf("%d %d", &i, &j);

	if (i > j)
		printf("i大于j\n");
	else
		printf("i小于j\n");

	retu</div>
                                </li>
                                <li><a href="/article/2768.htm"
                                       title="dictionary的使用要注意" target="_blank">dictionary的使用要注意</a>
                                    <span class="text-muted">dcj3sjt126com</span>
<a class="tag" taget="_blank" href="/search/IO/1.htm">IO</a>
                                    <div>NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:
                          user.user_id , @"id",
                          user.username , @"username",
         </div>
                                </li>
                                <li><a href="/article/2895.htm"
                                       title="Android 中的资源访问(Resource)" target="_blank">Android 中的资源访问(Resource)</a>
                                    <span class="text-muted">finally_m</span>
<a class="tag" taget="_blank" href="/search/xml/1.htm">xml</a><a class="tag" taget="_blank" href="/search/android/1.htm">android</a><a class="tag" taget="_blank" href="/search/String/1.htm">String</a><a class="tag" taget="_blank" href="/search/drawable/1.htm">drawable</a><a class="tag" taget="_blank" href="/search/color/1.htm">color</a>
                                    <div> 
简单的说,Android中的资源是指非代码部分。例如,在我们的Android程序中要使用一些图片来设置界面,要使用一些音频文件来设置铃声,要使用一些动画来显示特效,要使用一些字符串来显示提示信息。那么,这些图片、音频、动画和字符串等叫做Android中的资源文件。 
在Eclipse创建的工程中,我们可以看到res和assets两个文件夹,是用来保存资源文件的,在assets中保存的一般是原生</div>
                                </li>
                                <li><a href="/article/3022.htm"
                                       title="Spring使用Cache、整合Ehcache" target="_blank">Spring使用Cache、整合Ehcache</a>
                                    <span class="text-muted">234390216</span>
<a class="tag" taget="_blank" href="/search/spring/1.htm">spring</a><a class="tag" taget="_blank" href="/search/cache/1.htm">cache</a><a class="tag" taget="_blank" href="/search/ehcache/1.htm">ehcache</a><a class="tag" taget="_blank" href="/search/%40Cacheable/1.htm">@Cacheable</a>
                                    <div>Spring使用Cache 
  
  
       从3.1开始,Spring引入了对Cache的支持。其使用方法和原理都类似于Spring对事务管理的支持。Spring Cache是作用在方法上的,其核心思想是这样的:当我们在调用一个缓存方法时会把该方法参数和返回结果作为一个键值对存放在缓存中,等到下次利用同样的</div>
                                </li>
                                <li><a href="/article/3149.htm"
                                       title="当druid遇上oracle blob(clob)" target="_blank">当druid遇上oracle blob(clob)</a>
                                    <span class="text-muted">jackyrong</span>
<a class="tag" taget="_blank" href="/search/oracle/1.htm">oracle</a>
                                    <div>http://blog.csdn.net/renfufei/article/details/44887371 
 
众所周知,Oracle有很多坑, 所以才有了去IOE。 
 
在使用Druid做数据库连接池后,其实偶尔也会碰到小坑,这就是使用开源项目所必须去填平的。【如果使用不开源的产品,那就不是坑,而是陷阱了,你都不知道怎么去填坑】 
 
用Druid连接池,通过JDBC往Oracle数据库的</div>
                                </li>
                                <li><a href="/article/3276.htm"
                                       title="easyui datagrid pagination获得分页页码、总页数等信息" target="_blank">easyui datagrid pagination获得分页页码、总页数等信息</a>
                                    <span class="text-muted">ldzyz007</span>

                                    <div>var grid = $('#datagrid');  
var options = grid.datagrid('getPager').data("pagination").options;  
var curr = options.pageNumber;  
var total = options.total;  
var max =</div>
                                </li>
                                <li><a href="/article/3403.htm"
                                       title="浅析awk里的数组" target="_blank">浅析awk里的数组</a>
                                    <span class="text-muted">nigelzeng</span>
<a class="tag" taget="_blank" href="/search/%E4%BA%8C%E7%BB%B4%E6%95%B0%E7%BB%84/1.htm">二维数组</a><a class="tag" taget="_blank" href="/search/array/1.htm">array</a><a class="tag" taget="_blank" href="/search/%E6%95%B0%E7%BB%84/1.htm">数组</a><a class="tag" taget="_blank" href="/search/awk/1.htm">awk</a>
                                    <div>awk绝对是文本处理中的神器,它本身也是一门编程语言,还有许多功能本人没有使用到。这篇文章就单单针对awk里的数组来进行讨论,如何利用数组来帮助完成文本分析。 
  
有这么一组数据: 
   abcd,91#31#2012-12-31 11:24:00 
case_a,136#19#2012-12-31 11:24:00 
case_a,136#23#2012-12-31 1</div>
                                </li>
                                <li><a href="/article/3530.htm"
                                       title="搭建 CentOS 6 服务器(6) - TigerVNC" target="_blank">搭建 CentOS 6 服务器(6) - TigerVNC</a>
                                    <span class="text-muted">rensanning</span>
<a class="tag" taget="_blank" href="/search/centos/1.htm">centos</a>
                                    <div>安装GNOME桌面环境 
 
# yum groupinstall "X Window System" "Desktop" 
 
 
安装TigerVNC 
 
# yum -y install tigervnc-server tigervnc 
 
 
启动VNC服务 
 
# /etc/init.d/vncserver restart
# vncser</div>
                                </li>
                                <li><a href="/article/3657.htm"
                                       title="Spring 数据库连接整理" target="_blank">Spring 数据库连接整理</a>
                                    <span class="text-muted">tomcat_oracle</span>
<a class="tag" taget="_blank" href="/search/spring/1.htm">spring</a><a class="tag" taget="_blank" href="/search/bean/1.htm">bean</a><a class="tag" taget="_blank" href="/search/jdbc/1.htm">jdbc</a>
                                    <div>1、数据库连接jdbc.properties配置详解    jdbc.url=jdbc:hsqldb:hsql://localhost/xdb     jdbc.username=sa     jdbc.password=     jdbc.driver=不同的数据库厂商驱动,此处不一一列举     接下来,详细配置代码如下:      
Spring连接池      </div>
                                </li>
                                <li><a href="/article/3784.htm"
                                       title="Dom4J解析使用xpath java.lang.NoClassDefFoundError: org/jaxen/JaxenException异常" target="_blank">Dom4J解析使用xpath java.lang.NoClassDefFoundError: org/jaxen/JaxenException异常</a>
                                    <span class="text-muted">xp9802</span>

                                    <div>用Dom4J解析xml,以前没注意,今天使用dom4j包解析xml时在xpath使用处报错 
     异常栈:java.lang.NoClassDefFoundError: org/jaxen/JaxenException异常  
     导入包 jaxen-1.1-beta-6.jar 解决; 
&nb</div>
                                </li>
                </ul>
            </div>
        </div>
    </div>

<div>
    <div class="container">
        <div class="indexes">
            <strong>按字母分类:</strong>
            <a href="/tags/A/1.htm" target="_blank">A</a><a href="/tags/B/1.htm" target="_blank">B</a><a href="/tags/C/1.htm" target="_blank">C</a><a
                href="/tags/D/1.htm" target="_blank">D</a><a href="/tags/E/1.htm" target="_blank">E</a><a href="/tags/F/1.htm" target="_blank">F</a><a
                href="/tags/G/1.htm" target="_blank">G</a><a href="/tags/H/1.htm" target="_blank">H</a><a href="/tags/I/1.htm" target="_blank">I</a><a
                href="/tags/J/1.htm" target="_blank">J</a><a href="/tags/K/1.htm" target="_blank">K</a><a href="/tags/L/1.htm" target="_blank">L</a><a
                href="/tags/M/1.htm" target="_blank">M</a><a href="/tags/N/1.htm" target="_blank">N</a><a href="/tags/O/1.htm" target="_blank">O</a><a
                href="/tags/P/1.htm" target="_blank">P</a><a href="/tags/Q/1.htm" target="_blank">Q</a><a href="/tags/R/1.htm" target="_blank">R</a><a
                href="/tags/S/1.htm" target="_blank">S</a><a href="/tags/T/1.htm" target="_blank">T</a><a href="/tags/U/1.htm" target="_blank">U</a><a
                href="/tags/V/1.htm" target="_blank">V</a><a href="/tags/W/1.htm" target="_blank">W</a><a href="/tags/X/1.htm" target="_blank">X</a><a
                href="/tags/Y/1.htm" target="_blank">Y</a><a href="/tags/Z/1.htm" target="_blank">Z</a><a href="/tags/0/1.htm" target="_blank">其他</a>
        </div>
    </div>
</div>
<footer id="footer" class="mb30 mt30">
    <div class="container">
        <div class="footBglm">
            <a target="_blank" href="/">首页</a> -
            <a target="_blank" href="/custom/about.htm">关于我们</a> -
            <a target="_blank" href="/search/Java/1.htm">站内搜索</a> -
            <a target="_blank" href="/sitemap.txt">Sitemap</a> -
            <a target="_blank" href="/custom/delete.htm">侵权投诉</a>
        </div>
        <div class="copyright">版权所有 IT知识库 CopyRight © 2000-2050 E-COM-NET.COM , All Rights Reserved.
<!--            <a href="https://beian.miit.gov.cn/" rel="nofollow" target="_blank">京ICP备09083238号</a><br>-->
        </div>
    </div>
</footer>
<!-- 代码高亮 -->
<script type="text/javascript" src="/static/syntaxhighlighter/scripts/shCore.js"></script>
<script type="text/javascript" src="/static/syntaxhighlighter/scripts/shLegacy.js"></script>
<script type="text/javascript" src="/static/syntaxhighlighter/scripts/shAutoloader.js"></script>
<link type="text/css" rel="stylesheet" href="/static/syntaxhighlighter/styles/shCoreDefault.css"/>
<script type="text/javascript" src="/static/syntaxhighlighter/src/my_start_1.js"></script>





</body>

</html>