zoukankan      html  css  js  c++  java
  • istio 学习之 手动注入sidecar

    istio 创建pod的时候会给默认自动注入的命名空间 注入sidecar ,sidecar中包含envoy组件和pilot-agent组件

    ,这两个共同组成sidecar。

    这次的目的就是为了观察istio 注入的过程。

    首先我们新创建一个test 命名空间

    [root@istio-master test]# kubectl create namespace test
    namespace/test created

    写一个nginx.yaml

    [root@istio-master test]# vi nginx.yaml
    [root@istio-master test]# cat nginx.yaml 
    apiVersion: apps/v1
    kind: Deployment
    metadata: 
      name: test-nginx
      labels:
        name: test-nginx
    
    spec:
      replicas: 1
      selector: 
        matchLabels:
          app: test-nginx
      template:
        metadata:
          labels:
            app: test-nginx
        spec:
          containers:
          - name: nginx
            image: nginx:1.14-alpine
            imagePullPolicy: IfNotPresent
            ports:
            - containerPort: 80

    执行这个yml文件,创建一个nginx的pod

    [root@istio-master test]# kubectl create -f nginx.yaml -n test
    deployment.apps/test-nginx created

    查看这个pod已经创建完毕

    [root@istio-master test]# kubectl get po -n test
    NAME                         READY   STATUS    RESTARTS   AGE
    test-nginx-9ddbd4d55-c676x   1/1     Running   0          22s

    对这个pod进行手动注入sidecar。并且观察pod的变化

    [root@istio-master test]# istioctl kube-inject -f nginx.yaml | kubectl apply -f - -n test
    Warning: kubectl apply should be used on resource created by either kubectl create --save-config or kubectl apply
    deployment.apps/test-nginx configured
    [root@istio-master test]# kubectl get po -n test
    NAME                          READY   STATUS            RESTARTS   AGE
    test-nginx-7f945c7759-4g47d   0/2     PodInitializing   0          7s
    test-nginx-9ddbd4d55-c676x    1/1     Running           0          11m
    [root@istio-master test]# kubectl get po -n test
    NAME                          READY   STATUS            RESTARTS   AGE
    test-nginx-7f945c7759-4g47d   0/2     PodInitializing   0          10s
    test-nginx-9ddbd4d55-c676x    1/1     Running           0          11m
    [root@istio-master test]# kubectl get po -n test
    NAME                          READY   STATUS        RESTARTS   AGE
    test-nginx-7f945c7759-4g47d   2/2     Running       0          17s
    test-nginx-9ddbd4d55-c676x    0/1     Terminating   0          11m
    [root@istio-master test]# kubectl get po -n test
    NAME                          READY   STATUS        RESTARTS   AGE
    test-nginx-7f945c7759-4g47d   2/2     Running       0          23s
    test-nginx-9ddbd4d55-c676x    0/1     Terminating   0          11m
    [root@istio-master test]# kubectl get po -n test
    NAME                          READY   STATUS    RESTARTS   AGE

    可以观察到pod的变化 由最初的一个消失,变成两个带有两个container的pod,那么这个pod到底经历了什么呢

    1. 我们可以先观察这个注入后yml文件
    2. 在观察注入后的pod的详情

    第一步观察 注入后的yml 和之前发生了什么变化

    [root@istio-master test]# istioctl  kube-inject -f nginx.yaml > nginx-inject.yaml

    然后观察这个yml文件,因为这个文件很多我就截图来看下yml多了什么东西

    这个截图还是我们原来的nginx 的镜像没有太大变化

     下面这个是新生成的istio-proxy 

     这个镜像是一个isito-init 这个只是用于给nginx和isito-proxy创建一个网络环境配置ip地址然后就消失了,并不会占用资源

    为了证明 ngnix 和 isito-proxy  在同一个网络环境,我们再进入pod中的container 看看是否一样

    我们知道原来的nginx 只有一个 80 端口。那么现在肯定增加了好几个端口,来看看吧

    [root@istio-master test]# kubectl exec -it test-nginx-7f945c7759-4g47d -n test -c nginx -- netstat -ntlp
    Active Internet connections (only servers)
    Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
    tcp        0      0 0.0.0.0:15021           0.0.0.0:*               LISTEN      -
    tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      1/nginx: master pro
    tcp        0      0 0.0.0.0:15090           0.0.0.0:*               LISTEN      -
    tcp        0      0 127.0.0.1:15000         0.0.0.0:*               LISTEN      -
    tcp        0      0 0.0.0.0:15001           0.0.0.0:*               LISTEN      -
    tcp        0      0 0.0.0.0:15006           0.0.0.0:*               LISTEN      -
    tcp        0      0 :::15020                :::*                    LISTEN      -

    增加了好多 用来控制流量以及与代理进行通信的端口,这些都是istio-init 这个pod 做的事情

  • 相关阅读:
    ubuntu server 14.04和18.04挂载vmware共享文件夹
    Ubuntu 无法进行SSH连接,开启22端口
    ubuntu切换到root用户
    VMware Workstation 15 Pro 永久激活密钥
    idea静态资源的访问问题,如HTML,css,js的加载
    idea在Tomcat服务器加载html文件出现乱码的解决方案
    html,js 打开时出现 Uncaught TypeError: Cannot read property 'addEventListener' of null at register.js:24错误的解决方法
    js判断input输入是不是含有中文,或者判断输入是不是全是中文
    PHP连接前端from数据的错误,如源服务器未能找到目标资源的表示或者是不愿公开一个已经存在的资源表示。
    PHP与Tomcat运行前的配置。
  • 原文地址:https://www.cnblogs.com/ScarecrowAnBird/p/14668726.html
Copyright © 2011-2022 走看看