(10)kube-proxy部署

创建相关目录

# 3台master, 2台node
mkdir /k8s/kube-proxy

生成证书

创建配置文件

cd /opt/k8s-playbook/ssl
vi kube-proxy-csr.json
#######################################################
{
  "CN": "system:kube-proxy",
  "key": {
    "algo": "rsa",
    "size": 2048
  },
  "names": [
    {
      "C": "CN",
      "ST": "Shenzhen",
      "L": "Shenzhen",
      "O": "zhfi",
      "OU": "magina"
    }
  ]
}
#######################################################

生成

cfssl gencert -ca=ca.pem \
  -ca-key=ca-key.pem \
  -config=ca-config.json \
  -profile=kubernetes kube-proxy-csr.json | cfssljson -bare kube-proxy

分发

cp kube-proxy*.pem /etc/k8s/cert/

scp kube-proxy*.pem root@master-02:/etc/k8s/cert/
scp kube-proxy*.pem root@master-03:/etc/k8s/cert/
scp kube-proxy*.pem root@node-01:/etc/k8s/cert/
scp kube-proxy*.pem root@node-02:/etc/k8s/cert/

创建kube-proxy.kubeconfig

kubectl config set-cluster kubernetes \
  --certificate-authority=ca.pem \
  --embed-certs=true \
  --server=https://192.168.104.61:8443 \
  --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 config use-context default --kubeconfig=kube-proxy.kubeconfig

分发

cp kube-proxy.kubeconfig /etc/k8s/

scp kube-proxy.kubeconfig root@master-02:/etc/k8s/
scp kube-proxy.kubeconfig root@master-03:/etc/k8s/
scp kube-proxy.kubeconfig root@node-01:/etc/k8s/
scp kube-proxy.kubeconfig root@node-02:/etc/k8s/

创建kube-proxy-config.yaml

vi kube-proxy-config.yaml
#######################################################
kind: KubeProxyConfiguration
apiVersion: kubeproxy.config.k8s.io/v1alpha1
clientConnection:
  burst: 200
  kubeconfig: "/etc/k8s/kube-proxy.kubeconfig"
  qps: 100
bindAddress: 172.30.1.5
healthzBindAddress: 172.30.1.5:10256
metricsBindAddress: 172.30.1.5:10249
enableProfiling: true
clusterCIDR: 172.18.0.0/16
hostnameOverride: master-01
mode: "ipvs"
portRange: ""
iptables:
  masqueradeAll: false
ipvs:
  scheduler: rr
  excludeCIDRs: []
#######################################################
  • bindAddress: 换成本机的IP
  • healthzBindAddress: 本机IP:10256
  • metricsBindAddress: 本机IP:10249
  • clusterCIDR: 与/etc/k8s/kubelet-config.yamlpodCIDR参数对应
  • hostnameOverride: 本机主机名

创建kube-proxy.service

vi /etc/systemd/system/kube-proxy.service
#######################################################
[Unit]
Description=Kubernetes Kube-Proxy Server
Documentation=https://github.com/GoogleCloudPlatform/kubernetes
After=network.target

[Service]
WorkingDirectory=/k8s/kube-proxy
ExecStart=/opt/k8s/bin/kube-proxy \
  --config=/etc/k8s/kube-proxy-config.yaml \
  --logtostderr=true \
  --v=2
Restart=on-failure
RestartSec=5
LimitNOFILE=65536

[Install]
WantedBy=multi-user.target
#######################################################

复制二进制文件并启动

cd /opt/k8s-playbook/
cp kubernetes/server/bin/kube-proxy /opt/k8s/bin/

前提是已将相关组件解压到/opt/k8s-playbook/

scp /opt/k8s/bin/kube-proxy root@master-02:/opt/k8s/bin/
scp /opt/k8s/bin/kube-proxy root@master-03:/opt/k8s/bin/
scp /opt/k8s/bin/kube-proxy root@node-01:/opt/k8s/bin/
scp /opt/k8s/bin/kube-proxy root@node-02:/opt/k8s/bin/

# 三台master分别执行
chmod +x /opt/k8s/bin/kube-proxy

systemctl enable kube-proxy
systemctl start kube-proxy

查看ipvs路由规则

ipvsadm -ln

展示评论