当前位置: 首页 > 工具软件 > goproxy-shell > 使用案例 >

Kubernetes安装系列之Node-Kube-proxy安装

农飞星
2023-12-01

这篇文章整理以下Node节点的kube-proxy的安装与设定方法,本文以脚本的方式进行固化,内容仍然放在github的easypack上。

整体操作

kube-proxy的设定文件

[root@host131 shell]# cat /etc/k8s/kube-proxy.conf 
KUBE_PROXY_OPTS="--logtostderr=true \
--v=4 \
--log-dir=/var/log/kubernetes \
--config=/etc/k8s/kube-proxy-config.yaml"
[root@host131 shell]#

config设定文件

从1.10开始,很多参数都需要在config指定的文件中进行设定,设定示例如下

[root@host131 shell]# cat /etc/k8s/kube-proxy-config.yaml
kind: KubeProxyConfiguration
apiVersion: kubeproxy.config.k8s.io/v1alpha1
clientConnection:
  kubeconfig: "/etc/ssl/k8s/kube-proxy.kubeconfig"
bindAddress: 192.168.163.131
clusterCIDR: 172.200.0.0/16
healthzBindAddress: 192.168.163.131:10256
hostnameOverride: 192.168.163.131
metricsBindAddress: 192.168.163.131:10249
mode: "ipvs"
[root@host131 shell]# 

Systemd服务配置文件

[root@host131 shell]# cat /usr/lib/systemd/system/kube-proxy.service 
[Unit]
Description=Kubernetes Kube-Proxy Service
Documentation=https://github.com/GoogleCloudPlatform/kubernetes
After=docker.service
After=network.target

[Service]
WorkingDirectory=/var/lib/k8s/kube-proxy
EnvironmentFile=-/etc/k8s/kube-proxy.conf
ExecStart=/usr/local/bin/kube-proxy $KUBE_PROXY_OPTS
Restart=on-failure
RestartSec=5
LimitNOFILE=65536

[Install]
WantedBy=multi-user.target
[root@host131 shell]#

脚本示例

[root@host131 shell]# cat step8-3-install-kubeproxy.sh 
#!/bin/sh

. ./install.cfg

echo -e "\n##  kube-proxy service"
systemctl stop kube-proxy 2>/dev/null

mkdir -p ${ENV_KUBE_DIR_BIN} ${ENV_KUBE_DIR_ETC} ${ENV_KUBE_OPT_LOG_DIR} ${ENV_KUBE_PROXY_DIR_WORKING}
chmod 755 ${ENV_HOME_K8S}/*
cp -p ${ENV_HOME_K8S}/kube-proxy ${ENV_KUBE_DIR_BIN}
if [ $? -ne 0 ]; then
  echo "please check kube-proxy binary files existed in ${ENV_HOME_K8S}/ or not"
  exit 
fi

# create kube-proxy configuration file
cat >${ENV_KUBE_DIR_ETC}/${ENV_KUBE_PROXY_ETC} <<EOF
KUBE_PROXY_OPTS="--logtostderr=${ENV_KUBE_OPT_LOGTOSTDERR} \\
--v=${ENV_KUBE_OPT_LOG_LEVEL} \\
--log-dir=${ENV_KUBE_OPT_LOG_DIR} \\
--config=${ENV_KUBE_DIR_ETC}/${ENV_KUBE_PROXY_PROXY_CONFIG}"
EOF

cat >${ENV_KUBE_DIR_ETC}/${ENV_KUBE_PROXY_PROXY_CONFIG} <<EOF
kind: KubeProxyConfiguration
apiVersion: kubeproxy.config.k8s.io/v1alpha1
clientConnection:
  kubeconfig: "${ENV_SSL_K8S_DIR}/${ENV_KUBECONFIG_KUBEPROXY}"
bindAddress: ${ENV_KUBE_NODE_HOSTNAME}
clusterCIDR: ${ENV_KUBE_OPT_CLUSTER_IP_RANGE}
healthzBindAddress: ${ENV_KUBE_NODE_HOSTNAME}:${ENV_KUBE_PROXY_CONFIG_PORT_HEALTH}
hostnameOverride: ${ENV_KUBE_NODE_HOSTNAME}
metricsBindAddress: ${ENV_KUBE_NODE_HOSTNAME}:${ENV_KUBE_PROXY_CONFIG_PORT_METRICS}
mode: "${ENV_KUBE_PROXY_CONFIG_MODE}"
EOF

# Create the kube-proxy service.
cat >${ENV_KUBE_PROXY_SERVICE} <<EOF
[Unit]
Description=Kubernetes Kube-Proxy Service
Documentation=https://github.com/GoogleCloudPlatform/kubernetes
After=docker.service
After=network.target

[Service]
WorkingDirectory=${ENV_KUBE_PROXY_DIR_WORKING}
EnvironmentFile=-${ENV_KUBE_DIR_ETC}/${ENV_KUBE_PROXY_ETC}
ExecStart=${ENV_KUBE_DIR_BIN}/kube-proxy \$KUBE_PROXY_OPTS
Restart=on-failure
RestartSec=5
LimitNOFILE=65536

[Install]
WantedBy=multi-user.target
EOF

echo -e "\n##  daemon reload service "
systemctl daemon-reload
echo -e "\n##  start kube-proxy service "
systemctl start kube-proxy
echo -e "\n##  enable kube-proxy service " 
systemctl enable kube-proxy
echo -e "\n##  check  kube-proxy status"
systemctl status kube-proxy
[root@host131 shell]# 

执行示例

为了执行方便,在这些脚本外边在包一层,统一使用如下脚本进行管理

[root@host131 shell]# sh all-k8s-mgnt.sh install kubeproxy
## ACTION: install  Service: kubeproxy begins ...

##  kube-proxy service

##  daemon reload service 

##  start kube-proxy service 

##  enable kube-proxy service 

##  check  kube-proxy status
● kube-proxy.service - Kubernetes Kube-Proxy Service
   Loaded: loaded (/usr/lib/systemd/system/kube-proxy.service; enabled; vendor preset: disabled)
   Active: active (running) since Sun 2019-03-24 20:08:23 CST; 333ms ago
     Docs: https://github.com/GoogleCloudPlatform/kubernetes
 Main PID: 1456 (kube-proxy)
   CGroup: /system.slice/kube-proxy.service
           ├─1456 /usr/local/bin/kube-proxy --logtostderr=true --v=4 --log-dir=/var/log/kubernetes --config=/etc/k8s/kube-proxy-config.yaml
           └─1493 modprobe -va ip_vs

Mar 24 20:08:23 host131 kube-proxy[1456]: I0324 20:08:23.494868    1456 flags.go:33] FLAG: --proxy-port-range=""
Mar 24 20:08:23 host131 kube-proxy[1456]: I0324 20:08:23.494874    1456 flags.go:33] FLAG: --resource-container="/kube-proxy"
Mar 24 20:08:23 host131 kube-proxy[1456]: I0324 20:08:23.494878    1456 flags.go:33] FLAG: --skip-headers="false"
Mar 24 20:08:23 host131 kube-proxy[1456]: I0324 20:08:23.494882    1456 flags.go:33] FLAG: --stderrthreshold="2"
Mar 24 20:08:23 host131 kube-proxy[1456]: I0324 20:08:23.494887    1456 flags.go:33] FLAG: --udp-timeout="250ms"
Mar 24 20:08:23 host131 kube-proxy[1456]: I0324 20:08:23.494895    1456 flags.go:33] FLAG: --v="4"
Mar 24 20:08:23 host131 kube-proxy[1456]: I0324 20:08:23.494899    1456 flags.go:33] FLAG: --version="false"
Mar 24 20:08:23 host131 kube-proxy[1456]: I0324 20:08:23.494905    1456 flags.go:33] FLAG: --vmodule=""
Mar 24 20:08:23 host131 kube-proxy[1456]: I0324 20:08:23.494911    1456 flags.go:33] FLAG: --write-config-to=""
Mar 24 20:08:23 host131 kube-proxy[1456]: I0324 20:08:23.526599    1456 feature_gate.go:206] feature gates: &{map[]}
## ACTION: install  Service: kubeproxy ends  ...

[root@host131 shell]# 

这样所有的组件基本安装完毕,至于多节点,目前的脚本拷贝过去即可使用,后续会继续简化操作方式。

 类似资料: