Reference:
1. 文件 Dockerfile
FROM alpine
#FROM golang:alpine
COPY ld-2.17.so /lib64/ld-linux-x86-64.so.2
COPY kata-monitor /
COPY control /
ENTRYPOINT ["/kata-monitor"]
2. build镜像
# build镜像
格式:docker build -t ImageName:TagName dir
-t 给镜像指定Tag。ImageName 给镜像起的名称,TagName 给镜像起的Tag名。
Dir Dockerfile所在目录
示例:docker build -t registry.baidubce.com/bci/kata-monitor:v1.2 .
注意:末尾有个'.'点号,表示当前目录的Dockerfile文件。
# 查看镜像
docker images
===
命令输出:
REPOSITORY TAG IMAGE ID CREATED SIZE
registry.baidubce.com/bci/kata-monitor v1.6 4432357810cc 13 hours ago 42.95 MB
# 试运行镜像
docker run -it 4432357810cc
3. push镜像
# login登录容器镜像服务
docker login --username=[username] registry.baidubce.com
# push
docker push registry.baidubce.com/bci/kata-monitor:v1.2
4. 创建pod
示例:daemonset.yaml
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: kata-monitor
namespace: kube-system
spec:
selector:
matchLabels:
app: kata-monitor
template:
metadata:
labels:
app: kata-monitor
spec:
containers:
- name: kata-monitor
image: registry.baidubce.com/bci/kata-monitor:v1.2
args:
- 0.0.0.0:8090
command:
- /control
- start
volumeMounts:
- name: run
mountPath: /run
readOnly: true
- name: timezone
mountPath: /etc/localtime
readOnly: true
hostNetwork: true
volumes:
- name: run
hostPath:
path: /run
type: Directory
- name: timezone
hostPath:
path: /usr/share/zoneinfo/Asia/Shanghai
type: ""
附:
(1) control脚本
#!/bin/sh
#kubectl create configmap kubeconfig --from-file=../../cmd/node-agent/config -n kube-system
LISTEN_ADDRESS=$2
set -e
do_start() {
# start kata-monitor
/kata-monitor -listen-address $LISTEN_ADDRESS
}
do_status() {
pid=$(ps aux | grep kata-monitor | grep -v grep | awk -F" " '{print $1}')
ret=$?
if [ ${ret} -eq 0 -n "${pid}" ]; then
return $?
elif [ ${ret} -eq 1 ]; then
return 1
fi
}
case "${1}" in
start)
do_start
;;
stop)
do_stop
;;
status)
do_status
;;
*)
exit 1
;;
esac