安装部署运算节点服务(kube-proxy)

# 签发证书请求文件,200:
200 certs]# vi kube-proxy-csr.json
{
    "CN": "system:kube-proxy",
    "key": {
        "algo": "rsa",
        "size": 2048
    },
    "names": [
        {
            "C": "CN",
            "ST": "beijing",
            "L": "beijing",
            "O": "od",
            "OU": "ops"
        }
    ]
}
200 certs]# cfssl gencert -ca=ca.pem -ca-key=ca-key.pem -config=ca-config.json -profile=client kube-proxy-csr.json |cfssl-json -bare kube-proxy-client

# 分发证书,21/22机器:
cd /opt/kubernetes/server/bin/cert
cert]# scp hdss7-200:/opt/certs/kube-proxy-client.pem .
cert]# scp hdss7-200:/opt/certs/kube-proxy-client-key.pem .
cd ../conf/
# 21机器:
conf]# kubectl config set-cluster myk8s \
  --certificate-authority=/opt/kubernetes/server/bin/cert/ca.pem \
  --embed-certs=true \
  --server=https://10.4.7.10:7443 \
  --kubeconfig=kube-proxy.kubeconfig
conf]# kubectl config set-credentials kube-proxy \
  --client-certificate=/opt/kubernetes/server/bin/cert/kube-proxy-client.pem \
  --client-key=/opt/kubernetes/server/bin/cert/kube-proxy-client-key.pem \
  --embed-certs=true \
  --kubeconfig=kube-proxy.kubeconfig
conf]# kubectl config set-context myk8s-context \
  --cluster=myk8s \
  --user=kube-proxy \
  --kubeconfig=kube-proxy.kubeconfig
conf]# kubectl config use-context myk8s-context --kubeconfig=kube-proxy.kubeconfig
# 22机器
conf]# scp hdss7-21:/opt/kubernetes/server/bin/conf/kube-proxy.kubeconfig .
# 21/22机器:
cd
~]# lsmod |grep ip_vs
~]# vi ipvs.sh
#!/bin/bash
ipvs_mods_dir="/usr/lib/modules/$(uname -r)/kernel/net/netfilter/ipvs"
for i in $(ls $ipvs_mods_dir|grep -o "^[^.]*")
do
  /sbin/modinfo -F filename $i &>/dev/null
  if [ $? -eq 0 ];then
    /sbin/modprobe $i
  fi
done
~]# chmod +x ipvs.sh
~]# ./ipvs.sh
~]# lsmod |grep ip_vs

lsmod :显示已载入系统的模块

  • 后面带的管道符则是过滤出ip_vs来

chmod +x :给文件添加执行权限

./ipvs.sh :运行文件

# 21/22机器:
~]#cd /opt/kubernetes/server/bin/
# 注意修改对应的机器ip,有一处修改:hdss7-21
bin]# vi /opt/kubernetes/server/bin/kube-proxy.sh
#!/bin/sh
./kube-proxy \
  --cluster-cidr 172.7.0.0/16 \
  --hostname-override hdss7-21.host.com \
  --proxy-mode=ipvs \
  --ipvs-scheduler=nq \
  --kubeconfig ./conf/kube-proxy.kubeconfig
  
bin]# chmod +x kube-proxy.sh
bin]# mkdir -p /data/logs/kubernetes/kube-proxy
# 注意机器IP,有一处修改:kube-proxy-7-21]
bin]# vi /etc/supervisord.d/kube-proxy.ini
[program:kube-proxy-7-21]
command=/opt/kubernetes/server/bin/kube-proxy.sh                     ; the program (relative uses PATH, can take args)
numprocs=1                                                           ; number of processes copies to start (def 1)
directory=/opt/kubernetes/server/bin                                 ; directory to cwd to before exec (def no cwd)
autostart=true                                                       ; start at supervisord start (default: true)
autorestart=true                                                     ; retstart at unexpected quit (default: true)
startsecs=30                                                         ; number of secs prog must stay running (def. 1)
startretries=3                                                       ; max # of serial start failures (default 3)
exitcodes=0,2                                                        ; 'expected' exit codes for process (default 0,2)
stopsignal=QUIT                                                      ; signal used to kill process (default TERM)
stopwaitsecs=10                                                      ; max num secs to wait b4 SIGKILL (default 10)
user=root                                                            ; setuid to this UNIX account to run the program
redirect_stderr=true                                                 ; redirect proc stderr to stdout (default false)
stdout_logfile=/data/logs/kubernetes/kube-proxy/proxy.stdout.log     ; stderr log path, NONE for none; default AUTO
stdout_logfile_maxbytes=64MB                                         ; max # logfile bytes b4 rotation (default 50MB)
stdout_logfile_backups=4                                             ; # of stdout logfile backups (default 10)
stdout_capture_maxbytes=1MB                                          ; number of bytes in 'capturemode' (default 0)
stdout_events_enabled=false                                          ; emit events on stdout writes (default false)
bin]# supervisorctl update
bin]# yum install ipvsadm -y
bin]# ipvsadm -Ln
bin]# kubectl get svc

ipvsadm :用于设置、维护和检查Linux内核中虚拟服务器列表的命令

ipvsadm -Ln :查看当前配置的虚拟服务和各个RS的权重

# 验证一下集群,21机器(在任意节点机器,我选的是21):
cd
~]# vi /root/nginx-ds.yaml
apiVersion: extensions/v1beta1
kind: DaemonSet
metadata:
  name: nginx-ds
spec:
  template:
    metadata:
      labels:
        app: nginx-ds
    spec:
      containers:
      - name: my-nginx
        image: harbor.od.com/public/nginx:v1.7.9
        ports:
        - containerPort: 80
    
~]# kubectl create -f nginx-ds.yaml
# out:daemonset.extensions/nginx-ds created
~]# kubectl get pods -o wide
# 以下是成功的状态,在21/22机器都可以查到

注意,如果你的pod的wide22的也在21上或者类似情况,那就是你的vi /etc/docker/daemon.json没改好机器名,需要重新做过全部机器

kubectl create -f :通过配置文件名或stdin创建一个集群资源对象

kubectl get ... -o wide :显示网络情况

nginx-ds.yaml解析:

  • 可以参考这篇文章点击跳转,这里的nginx-ds.yaml建议自己手敲一遍,敲的同时要知道自己敲的是什么,记住,YAML语法不允许使用Tab键,只允许空格

完成,此时你已经部署好K8S集群,当然只有集群还远远不够,我们还需要更多的东西才能组成我们的PaaS服务。