对于 K8 的专家来说,这听起来像是一个非常愚蠢的问题。但是我已经为此苦苦挣扎了一段时间,因此是下面的问题。
我正在尝试通过 Minikube 和 docker 在本地部署一个简单的 Kubernetes 应用程序来测试 sidecar 容器模式。
让我们从边车容器元素开始:
文件
FROM python:3.6-alpine
RUN pip install boto3==1.14.20
RUN pip install --upgrade awscli s3cmd
ENV APP_HOME_DIR=/home/sidecar
RUN mkdir $APP_HOME_DIR
ADD run.sh $APP_HOME_DIR
ADD s3_sync.py $APP_HOME_DIR
RUN chmod +x $APP_HOME_DIR/s3_sync.py
RUN chmod +x $APP_HOME_DIR/run.sh
ENV BUCKET_NAME=
ENV PROJECT_NAME=
ENV FEATURE_BRANCH=
ENV LOCAL_DIR=
WORKDIR $APP_HOME_DIR
ENTRYPOINT ["./run.sh"]
run.sh
#!/bin/sh
while true
do
echo "Triggering an S3-SYNC"
python /home/sidecar/s3_sync.py -b $BUCKET_NAME -p $PROJECT_NAME -f $FEATURE_BRANCH -l $LOCAL_DIR
sleep 10
done
以及 python 文件s3_sync.py的简化版本:
import logging
import argparse
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s [%(levelname)s] %(message)s",
handlers=[logging.FileHandler("debug.log"), logging.StreamHandler()],
)
logger = logging.getLogger(__name__)
MASTER = "master"
def main():
bucket_name = args.bucket_name
project_name = args.project_name
branch = args.feature_branch
local_dir = args.local_dir
sync_type = "production" if branch == MASTER else "review"
logger.info(f"S3-SYNC starting for {sync_type} environment")
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("-b", "--bucket_name", help="s3 bucket name", required=True)
parser.add_argument("-p", "--project_name", help="project name to sync", default="")
parser.add_argument("-f", "--feature_branch", help="git feature branch name", default="master")
parser.add_argument("-l", "--local_dir", help="local dir where to sync the s3 objects", required=True)
args = parser.parse_args()
main()
如果我构建上面的内容并运行它:
docker build -t sidecar_python .
docker run -e BUCKET_NAME=MYBUCKET -e PROJECT_NAME=MYPROJECT -e FEATURE_BRANCH=MYBRANCH -e LOCAL_DIR=/home sidecar_python
事情进展顺利。
喵喔喔
相关分类