构建私有仓库 flink image 镜像
准备flink-*.tar.gz
可以自己编译,或者下载
编译
cd ${flink-root}
mvn install -DskipTests
# 编译成功后,压缩成tar.gz
cd ./flink-dist/target/
tar -cvf flink-1.18-SNAPSHOT-bin.tar.gz ./flink-1.18-SNAPSHOT-bin
下载
准备 gosu
docker-entrypoint.sh 需要使用到 gosu
https://github.com/tianon/gosu/releases/download/1.11/gosu-amd64
https://github.com/tianon/gosu/releases/download/1.11/gosu-amd64.asc
Dockefile
flink原始的 https://github.com/apache/flink-docker
我这边换了一个底层镜像,其他的都是类似
FROM openjdk:8-jre
ENV FLINK_TAR=flink-1.18-SNAPSHOT.tar.gz
COPY gosu-amd64 /usr/local/bin/gosu
COPY gosu-amd64.asc /usr/local/bin/gosu.asc
# Install dependencies
RUN set -ex; \
apt-get update; \
apt-get -y install gpg libsnappy1v5 gettext-base libjemalloc-dev; \
rm -rf /var/lib/apt/lists/*
COPY $FLINK_TAR $FLINK_HOME
# Install dependencies
ENV GOSU_VERSION 1.11
RUN set -ex; \
export GNUPGHOME="$(mktemp -d)"; \
for server in ha.pool.sks-keyservers.net $(shuf -e \
hkp://p80.pool.sks-keyservers.net:80 \
keyserver.ubuntu.com \
hkp://keyserver.ubuntu.com:80 \
pgp.mit.edu) ; do \
gpg --batch --keyserver "$server" --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4 && break || : ; \
done && \
gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu; \
gpgconf --kill all; \
rm -rf "$GNUPGHOME" /usr/local/bin/gosu.asc; \
chmod +x /usr/local/bin/gosu; \
gosu nobody true
# Prepare environment
ENV FLINK_HOME=/opt/flink
ENV PATH=$FLINK_HOME/bin:$PATH
RUN groupadd --system --gid=9999 flink && \
useradd --system --home-dir $FLINK_HOME --uid=9999 --gid=flink flink
WORKDIR $FLINK_HOME
ENV FLINK_HOME=/opt/flink
# Change
COPY $FLINK_TAR $FLINK_HOME
# Install Flink
RUN set -ex; \
tar -xf $FLINK_TAR -C $FLINK_HOME --strip-components=1; \
rm $FLINK_TAR; \
chown -R flink:flink .; \
sed -i 's/rest.address: localhost/rest.address: 0.0.0.0/g' $FLINK_HOME/conf/flink-conf.yaml; \
sed -i 's/rest.bind-address: localhost/rest.bind-address: 0.0.0.0/g' $FLINK_HOME/conf/flink-conf.yaml; \
sed -i 's/jobmanager.bind-host: localhost/jobmanager.bind-host: 0.0.0.0/g' $FLINK_HOME/conf/flink-conf.yaml; \
sed -i 's/taskmanager.bind-host: localhost/taskmanager.bind-host: 0.0.0.0/g' $FLINK_HOME/conf/flink-conf.yaml; \
sed -i '/taskmanager.host: localhost/d' $FLINK_HOME/conf/flink-conf.yaml;
# Configure container
COPY docker-entrypoint.sh /
ENTRYPOINT ["/docker-entrypoint.sh"]
EXPOSE 6123 8081
CMD ["help"]
编译docker 镜像
ls -al ./
# 结构如下
-rwxrwxr-x 1 chouc chouc 5285 4月 14 15:22 docker-entrypoint.sh
-rw-rw-r-- 1 chouc chouc 3021 4月 18 15:20 Dockerfile
-rw-rw-r-- 1 chouc chouc 540866560 4月 15 19:38 flink-1.18-SNAPSHOT.tar.gz
-rw-rw-r-- 1 chouc chouc 2294944 4月 17 16:19 gosu-amd64
-rw-rw-r-- 1 chouc chouc 566 4月 17 17:04 gosu-amd64.asc
docker build ./ -t tmaster:5000/flink:1.18-SNAPSHOP
push 到私有仓库
docker push tmaster:5000/flink:1.18-SNAPSHOT
Demo
在flink-conf.yaml修改镜像
kubernetes.container.image.ref: tmaster:5000/flink:1.18-SNAPSHOT
在linux 上启动 kubernetes-session
./bin/kubernetes-session.sh