Skip to content

Commit

Permalink
Merge pull request #11 from wrype/opti-bin-path
Browse files Browse the repository at this point in the history
feat(k8s): 可以自定义二进制文件路径
  • Loading branch information
muicoder authored Dec 28, 2023
2 parents 25117f8 + 1bc3dd1 commit 1f252a6
Show file tree
Hide file tree
Showing 15 changed files with 45 additions and 35 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.idea
.idea
.vscode
2 changes: 1 addition & 1 deletion containerd/etc/containerd.service.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ After=network.target local-fs.target

[Service]
ExecStartPre=-/sbin/modprobe overlay
ExecStart=/usr/bin/containerd
ExecStart={{ default "/usr/bin" .BIN_DIR }}/containerd

Type=notify
Delegate=yes
Expand Down
21 changes: 11 additions & 10 deletions containerd/scripts/clean-containerd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
cd "$(dirname "$0")" >/dev/null 2>&1 || exit
source common.sh
storage=${1:-/var/lib/containerd}
readonly BIN_DIR=${BIN_DIR:-/usr/bin}
systemctl stop containerd
systemctl disable containerd
rm -rf /etc/containerd
Expand All @@ -24,17 +25,17 @@ rm -rf $storage
rm -rf /run/containerd/containerd.sock
rm -rf /var/lib/nerdctl

rm -f /usr/bin/containerd
rm -f /usr/bin/containerd-stress
rm -f /usr/bin/containerd-shim
rm -f /usr/bin/containerd-shim-runc-v1
rm -f /usr/bin/containerd-shim-runc-v2
rm -f /usr/bin/crictl
rm -f ${BIN_DIR}/containerd
rm -f ${BIN_DIR}/containerd-stress
rm -f ${BIN_DIR}/containerd-shim
rm -f ${BIN_DIR}/containerd-shim-runc-v1
rm -f ${BIN_DIR}/containerd-shim-runc-v2
rm -f ${BIN_DIR}/crictl
rm -f /etc/crictl.yaml
rm -f /usr/bin/ctr
rm -f /usr/bin/ctd-decoder
rm -f /usr/bin/runc
rm -f /usr/bin/nerdctl
rm -f ${BIN_DIR}/ctr
rm -f ${BIN_DIR}/ctd-decoder
rm -f ${BIN_DIR}/runc
rm -f ${BIN_DIR}/nerdctl

rm -rf /opt/containerd
rm -rf /etc/ld.so.conf.d/containerd.conf
Expand Down
5 changes: 3 additions & 2 deletions containerd/scripts/init-containerd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@ cd "$(dirname "$0")" >/dev/null 2>&1 || exit
source common.sh
registry_domain=${1:-sealos.hub}
registry_port=${2:-5000}
readonly BIN_DIR=${BIN_DIR:-/usr/bin}

mkdir -p /opt/containerd && tar -zxf ../cri/libseccomp.tar.gz -C /opt/containerd
echo "/opt/containerd/lib" >/etc/ld.so.conf.d/containerd.conf
ldconfig
[ -d /etc/containerd/certs.d/ ] || mkdir /etc/containerd/certs.d/ -p
cp ../etc/containerd.service /etc/systemd/system/
tar -zxf ../cri/cri-containerd.tar.gz -C /
tar -zxf ../cri/cri-containerd.tar.gz --strip-components 2 -C ${BIN_DIR}
# shellcheck disable=SC2046
chmod a+x $(tar -tf ../cri/cri-containerd.tar.gz | while read -r binary; do echo "/usr/bin/${binary##*/}"; done | xargs)
chmod a+x $(tar -tf ../cri/cri-containerd.tar.gz | while read -r binary; do echo "${BIN_DIR}/${binary##*/}"; done | xargs)
systemctl enable containerd.service
cp ../etc/config.toml /etc/containerd
mkdir -p /etc/containerd/certs.d/$registry_domain:$registry_port
Expand Down
2 changes: 1 addition & 1 deletion k8s/etc/10-kubeadm.conf.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ Environment="KUBELET_EXTRA_ARGS= \
{{ if or (not .SEALOS_SYS_KUBE_VERSION) (eq .SEALOS_SYS_KUBE_VERSION "") (not (semverCompare "^1.27.0" .SEALOS_SYS_KUBE_VERSION)) }}--pod-infra-container-image={{ .registryDomain }}:{{ .registryPort }}/{{ .sandboxImage }}{{ end }} \
--runtime-request-timeout=15m --container-runtime-endpoint=unix://{{ .SEALOS_SYS_CRI_ENDPOINT }} --image-service-endpoint=unix:///var/run/image-cri-shim.sock"
ExecStart=
ExecStart=/usr/bin/kubelet $KUBELET_KUBECONFIG_ARGS $KUBELET_CONFIG_ARGS $KUBELET_KUBEADM_ARGS $KUBELET_EXTRA_ARGS
ExecStart={{ default "/usr/bin" .BIN_DIR }}/kubelet $KUBELET_KUBECONFIG_ARGS $KUBELET_CONFIG_ARGS $KUBELET_KUBEADM_ARGS $KUBELET_EXTRA_ARGS
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Description=image-cri-shim

[Service]
ExecStart=/usr/bin/image-cri-shim -f /etc/image-cri-shim.yaml
ExecStart={{ default "/usr/bin" .BIN_DIR }}/image-cri-shim -f /etc/image-cri-shim.yaml
Restart=always
StartLimitInterval=0
RestartSec=10
Expand Down
6 changes: 3 additions & 3 deletions k8s/etc/kubelet.service → k8s/etc/kubelet.service.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ Description=kubelet: The Kubernetes Node Agent
Documentation=http://kubernetes.io/docs/

[Service]
ExecStart=/usr/bin/kubelet
ExecStartPre=-/usr/bin/kubelet-pre-start.sh
ExecStopPost=-/usr/bin/kubelet-post-stop.sh
ExecStart={{ default "/usr/bin" .BIN_DIR }}/kubelet
ExecStartPre=-{{ default "/usr/bin" .BIN_DIR }}/kubelet-pre-start.sh
ExecStopPost=-{{ default "/usr/bin" .BIN_DIR }}/kubelet-post-stop.sh
Restart=always
StartLimitInterval=0
RestartSec=10
Expand Down
13 changes: 7 additions & 6 deletions k8s/scripts/clean-kube.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,17 @@
# limitations under the License.
cd "$(dirname "$0")" >/dev/null 2>&1 || exit
source common.sh
readonly BIN_DIR=${BIN_DIR:-/usr/bin}
systemctl stop kubelet
systemctl disable kubelet
systemctl daemon-reload

rm -f /usr/bin/conntrack
rm -f /usr/bin/kubelet-pre-start.sh
rm -f /usr/bin/kubelet-post-stop.sh
rm -f /usr/bin/kubeadm
rm -f /usr/bin/kubectl
rm -f /usr/bin/kubelet
rm -f ${BIN_DIR}/conntrack
rm -f ${BIN_DIR}/kubelet-pre-start.sh
rm -f ${BIN_DIR}/kubelet-post-stop.sh
rm -f ${BIN_DIR}/kubeadm
rm -f ${BIN_DIR}/kubectl
rm -f ${BIN_DIR}/kubelet

sed -i '/ # sealos/d' /etc/sysctl.conf
sealos_b='### sealos begin ###'
Expand Down
3 changes: 2 additions & 1 deletion k8s/scripts/clean-shim.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@
# limitations under the License.
cd "$(dirname "$0")" >/dev/null 2>&1 || exit
source common.sh
readonly BIN_DIR=${BIN_DIR:-/usr/bin}
systemctl stop image-cri-shim
systemctl disable image-cri-shim
rm -rf /etc/systemd/system/image-cri-shim.service
systemctl daemon-reload
rm -f /usr/bin/image-cri-shim
rm -f ${BIN_DIR}/image-cri-shim
rm -f /etc/image-cri-shim.yaml
rm -f /var/lib/image-cri-shim
logger "clean shim success"
3 changes: 2 additions & 1 deletion k8s/scripts/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,9 @@ check_file_exits() {
}

check_port_inuse() {
readonly BIN_DIR=${BIN_DIR:-/usr/bin}
if ! command_exists lsof; then
cp -au ../opt/lsof /usr/bin
cp -au ../opt/lsof ${BIN_DIR}
fi
logger "Check port kubelet port 10249..10259, reserved port 5050..5054 inuse. Please wait..."
for port in {10249..10259} {5050..5054}; do
Expand Down
9 changes: 5 additions & 4 deletions k8s/scripts/init-kube.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.
cd "$(dirname "$0")" >/dev/null 2>&1 || exit
readonly BIN_DIR=${BIN_DIR:-/usr/bin}

# localhost for hosts
grep 127.0.0.1 <(grep localhost /etc/hosts) || echo "127.0.0.1 localhost" >>/etc/hosts
grep ::1 <(grep localhost /etc/hosts) || echo "::1 localhost" >>/etc/hosts

cp -a ../scripts/kubelet-pre-start.sh /usr/bin
cp -a ../scripts/kubelet-post-stop.sh /usr/bin
cp -a ../scripts/kubelet-pre-start.sh ${BIN_DIR}
cp -a ../scripts/kubelet-post-stop.sh ${BIN_DIR}

source common.sh
disable_firewalld
Expand All @@ -30,7 +31,7 @@ cat ../etc/sysctl.d/*.conf | sort | uniq | while read -r str; do
v=${str#*=}
echo "$k=$v # sealos"
done >>/etc/sysctl.conf
bash /usr/bin/kubelet-pre-start.sh
bash ${BIN_DIR}/kubelet-pre-start.sh
sealos_b='### sealos begin ###'
sealos_e='### sealos end ###'
if ! grep -E "($sealos_b|$sealos_e)" /etc/security/limits.conf >/dev/null 2>&1; then
Expand All @@ -41,7 +42,7 @@ if ! grep -E "($sealos_b|$sealos_e)" /etc/security/limits.conf >/dev/null 2>&1;
} >>/etc/security/limits.conf
fi

cp -a ../bin/* /usr/bin
cp -a ../bin/* ${BIN_DIR}
#need after cri-shim
logger "pull pause image ${registryDomain}:${registryPort}/${sandboxImage}"
crictl pull ${registryDomain}:${registryPort}/${sandboxImage}
Expand Down
3 changes: 2 additions & 1 deletion k8s/scripts/init-shim.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
# limitations under the License.
cd "$(dirname "$0")" >/dev/null 2>&1 || exit
source common.sh
readonly BIN_DIR=${BIN_DIR:-/usr/bin}
cp -rf ../etc/image-cri-shim.service /etc/systemd/system/
cp -rf ../etc/image-cri-shim.yaml /etc
cp -rf ../cri/image-cri-shim /usr/bin
cp -rf ../cri/image-cri-shim ${BIN_DIR}
[ -f ../etc/crictl.yaml ] && cp -rf ../etc/crictl.yaml /etc
systemctl enable image-cri-shim.service
systemctl daemon-reload
Expand Down
2 changes: 1 addition & 1 deletion registry/etc/registry.service.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Description=registry: The sealos registry
Documentation=https://www.sealos.io/docs/Intro

[Service]
ExecStart=/usr/bin/registry serve {{ .registryConfig }}/registry_config.yml
ExecStart={{ default "/usr/bin" .BIN_DIR }}/registry serve {{ .registryConfig }}/registry_config.yml
Restart=always
StartLimitInterval=0
RestartSec=10
Expand Down
3 changes: 2 additions & 1 deletion registry/scripts/clean-registry.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# limitations under the License.
cd "$(dirname "$0")" >/dev/null 2>&1 || exit
source common.sh
readonly BIN_DIR=${BIN_DIR:-/usr/bin}
# prepare registry storage as directory
cd "$(dirname "$0")" || error "error for $0"

Expand All @@ -22,7 +23,7 @@ readonly CONFIG=${2:-/etc/registry}

check_service stop registry
rm -f /etc/systemd/system/registry.service
rm -f /usr/bin/registry
rm -f ${BIN_DIR}/registry

rm -rf "$DATA"
rm -rf "$CONFIG"
Expand Down
3 changes: 2 additions & 1 deletion registry/scripts/init-registry.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ source common.sh

readonly DATA=${1:-/var/lib/registry}
readonly CONFIG=${2:-/etc/registry}
readonly BIN_DIR=${BIN_DIR:-/usr/bin}

mkdir -p "$DATA" "$CONFIG"

cp -a ../etc/registry.service /etc/systemd/system/
cp -au ../cri/registry /usr/bin/
cp -au ../cri/registry ${BIN_DIR}/

cp -a ../etc/registry_config.yml "$CONFIG"
cp -a ../etc/registry_htpasswd "$CONFIG"
Expand Down

0 comments on commit 1f252a6

Please sign in to comment.