(八)kubernetes集群搭建(二进制方式)之--node部署kube-proxy

kubernetes集群搭建(二进制方式)之--node部署kube-proxy

    • 1.创建配置文件
    • 2.配置参数文件
    • 3.生成kube-proxy证书
    • 4.生成kubeconfig文件
    • 5.systemd管理kube-proxy
    • 6.开启并设置开机自启

node包括的组件

  • etcd 用于存储(已安装)
  • docker (已安装)
  • kubelet (已安装)
  • kube-proxy (本章安装)

1.创建配置文件

cat > /data/kubernetes/cfg/kube-proxy.conf << EOF
KUBE_PROXY_OPTS="--logtostderr=false \\
--v=2 \\
--log-dir=/data/kubernetes/logs \\
--config=/data/kubernetes/cfg/kube-proxy-config.yml"
EOF

2.配置参数文件

cat > /data/kubernetes/cfg/kube-proxy-config.yml << EOF
kind: KubeProxyConfiguration
apiVersion: kubeproxy.config.k8s.io/v1alpha1
bindAddress: 0.0.0.0
metricsBindAddress: 0.0.0.0:10249
clientConnection:
  kubeconfig: /data/kubernetes/cfg/kube-proxy.kubeconfig
hostnameOverride: k8snode1
clusterCIDR: 10.0.0.0/24
EOF

3.生成kube-proxy证书

master节点中操作

cd ~/TLS/k8s/
cat > kube-proxy-csr.json<< EOF
{
    "CN": "system:kube-proxy",
    "hosts": [],
    "key": {
        "algo": "rsa",
        "size": 2048
    },
    "names": [{
        "C": "CN",
        "L": "BeiJing",
        "ST": "BeiJing",
        "O": "k8s",
        "OU": "System"
    }]
}
EOF
cfssl gencert -ca=ca.pem -ca-key=ca-key.pem -config=ca-config.json -profile=kubernetes kube-proxy-csr.json | cfssljson -bare kube-proxy

拷贝到node节点

scp ~/TLS/k8s/kube-proxy*pem root@172.21.32.15:/data/kubernetes/ssl/

4.生成kubeconfig文件

KUBE_APISERVER="https://192.168.80.134:6443"
kubectl config set-cluster kubernetes \
--certificate-authority=/data/kubernetes/ssl/ca.pem \
--embed-certs=true \
--server=${KUBE_APISERVER} \
--kubeconfig=kube-proxy.kubeconfig
kubectl config set-credentials kube-proxy \
--client-certificate=./kube-proxy.pem \
--client-key=./kube-proxy-key.pem \
--embed-certs=true \
--kubeconfig=kube-proxy.kubeconfig
kubectl config set-context default \
--cluster=kubernetes \
--user=kube-proxy \
--kubeconfig=kube-proxy.kubeconfig
kubectl create clusterrolebinding kube-proxy   --clusterrole=system:node-bootstrapper   --user=kube-proxy
kubectl config use-context default --kubeconfig=kube-proxy.kubeconfig

拷贝到node节点的配置中

scp kube-proxy.kubeconfig root@172.21.32.15:/data/kubernetes/cfg/

5.systemd管理kube-proxy

cat > /usr/lib/systemd/system/kube-proxy.service << EOF
[Unit]
Description=Kubernetes Proxy
After=network.target
[Service]
EnvironmentFile=/data/kubernetes/cfg/kube-proxy.conf
ExecStart=/data/kubernetes/bin/kube-proxy \$KUBE_PROXY_OPTS
Restart=on-failure
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
EOF

6.开启并设置开机自启

systemctl daemon-reload
systemctl start kube-proxy
systemctl enable kube-proxy
systemctl status kube-proxy

你可能感兴趣的:(kubernetes,工具,服务搭建,kubernetes)