k8x/systemd/install_kube_proxy.sh

86 lines
2.4 KiB
Bash
Raw Permalink Normal View History

2024-05-17 21:45:52 -04:00
#!/bin/bash
echo ""
echo "... ] INSTALLING KUBE PROXY [ ..."
HOME=$( cd "$(dirname "$0")" && pwd )
source $HOME/../config
systemctl stop kube-proxy
gzip -v -c -d $HOME/../blobs/kube-proxy.gz > /usr/local/bin/kube-proxy
chmod +x /usr/local/bin/kube-proxy
#generate kube-proxy's kubeconfig file
rm ${CONF_DIR}/kube-proxy/kubeconfig
TOKEN=`cat ${CA_DIR}/kube-proxy.token`
kubectl config set-cluster ${CLUSTER_NAME}.virtual.local --certificate-authority=${CA_DIR}/ca.crt --embed-certs=true --server=https://localhost:16443 --kubeconfig=${CONF_DIR}/kube-proxy/kubeconfig
kubectl config set-credentials kube-proxy --client-certificate=${CA_DIR}/kube-proxy.crt --client-key=${CA_DIR}/kube-proxy.key --embed-certs=true --token=$TOKEN --kubeconfig=${CONF_DIR}/kube-proxy/kubeconfig
kubectl config set-context ${CLUSTER_NAME}.virtual.local --cluster=${CLUSTER_NAME}.virtual.local --user=kube-proxy --kubeconfig=${CONF_DIR}/kube-proxy/kubeconfig
kubectl config use-context ${CLUSTER_NAME}.virtual.local --kubeconfig=${CONF_DIR}/kube-proxy/kubeconfig
#generate kube-proxy's config file
rm ${CONF_DIR}/kube-proxy/kube-proxy-config.yaml
cat <<EOF | tee ${CONF_DIR}/kube-proxy/kube-proxy-config.yaml
apiVersion: kubeproxy.config.k8s.io/v1alpha1
bindAddress: ${NODE_IP}
clientConnection:
acceptContentTypes: ""
burst: 10
contentType: application/vnd.kubernetes.protobuf
kubeconfig: "${CONF_DIR}/kube-proxy/kubeconfig"
qps: 5
clusterCIDR: ""
configSyncPeriod: 15m0s
conntrack:
max: 0
maxPerCore: 32768
min: 131072
tcpCloseWaitTimeout: 1h0m0s
tcpEstablishedTimeout: 24h0m0s
enableProfiling: false
healthzBindAddress: ${NODE_IP}:10256
iptables:
masqueradeAll: false
masqueradeBit: 14
minSyncPeriod: 0s
syncPeriod: 30s
ipvs:
excludeCIDRs: null
minSyncPeriod: 0s
scheduler: ""
syncPeriod: 30s
kind: KubeProxyConfiguration
metricsBindAddress: 127.0.0.1:10249
mode: "iptables"
clusterCIDR: "${CNI_NET}"
nodePortAddresses: null
oomScoreAdj: -999
portRange: ""
resourceContainer: /kube-proxy
udpIdleTimeout: 250ms
EOF
cat <<EOF | tee /etc/systemd/system/kube-proxy.service
[Unit]
Description=Kubernetes Proxy
After=network.target
[Service]
ExecStart=/usr/local/bin/kube-proxy \\
--config=${CONF_DIR}/kube-proxy/kube-proxy-config.yaml \\
--master=https://localhost:16443 \\
--logtostderr=true \\
--v=2
Restart=on-failure
RestartSec=5
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable kube-proxy
systemctl start kube-proxy