Deploying Personal AI agent with Kubernetes
After I build the AI app, the next step is to deploy it using Kubernetes. Streamlit provides the steps here https://docs.streamlit.io/deploy/tutorials/kubernetes
You are likely to run into issues, here is the step by step guide. Please create the Docker file per the link above.
FROM python:3.9-slim
RUN groupadd --gid 1000 appuser \
&& useradd --uid 1000 --gid 1000 -ms /bin/bash appuser
RUN pip3 install --no-cache-dir --upgrade \
pip \
virtualenv
RUN apt-get update && apt-get install -y \
build-essential \
software-properties-common \
git
USER appuser
WORKDIR /home/appuser
RUN git clone https://github.com/streamlit/streamlit-example.git app
ENV VIRTUAL_ENV=/home/appuser/venv
RUN virtualenv ${VIRTUAL_ENV}
RUN . ${VIRTUAL_ENV}/bin/activate && pip install -r app/requirements.txt
EXPOSE 8501
COPY run.sh /home/appuser
ENTRYPOINT ["./run.sh"]
First, install gcloud command line tools.
% brew install --cask google-cloud-sdk
% gcloud --version
Google Cloud SDK 515.0.0
bq 2.1.14
core 2025.03.14
gcloud-crc32c 1.0.0
gsutil 5.33
The next step is to configure-docker
% gcloud auth configure-docker
Adding credentials for all GCR repositories.
WARNING: A long list of credential helpers may cause delays running 'docker build'. We recommend passing the registry name to configure only the registry you are using.
After update, the following will be written to your Docker config file located at [/Users/guoyi/.docker/config.json]:
{
"credHelpers": {
"gcr.io": "gcloud",
"us.gcr.io": "gcloud",
"eu.gcr.io": "gcloud",
"asia.gcr.io": "gcloud",
"staging-k8s.gcr.io": "gcloud",
"marketplace.gcr.io": "gcloud"
}
}
Do you want to continue (Y/n)? y
Docker configuration file updated.
The third step is to build the docker image. You will need your Google Project ID from https://console.cloud.google.com/home/dashboard .
% docker build --platform linux/amd64 -t gcr.io/personal-ai-assistant-454604/personal-ai-assistant:v1 .
[+] Building 117.7s (15/15) FINISHED docker:desktop-linux
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 663B 0.0s
=> [internal] load metadata for docker.io/library/python:3.9-slim 4.5s
=> [auth] library/python:pull token for registry-1.docker.io 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [1/9] FROM docker.io/library/python:3.9-slim@sha256:e52ca5f579cc58fed41efcbb55a0ed5dccf6c7a156cba76acfb4ab42fc19dd00 2.1s
-----
View build details: docker-desktop://dashboard/build/desktop-linux/desktop-linux/d3lppzqh3lmsavm4ahgc58bql
领英推荐
The fourth step is to create a repo here https://cloud.google.com/artifact-registry/docs/repositories/create-repos . I named the same as the project as to be in sync.
The fifth step is to perform a login and set your project.
% gcloud auth login
% gcloud config set project personal-ai-assistant-454604
Updated property [core/project].
The sixth step is to enable the service "containerregistry"
% gcloud services enable containerregistry.googleapis.com
Operation "operations/acf.p2-720756607394-2c7217b6-50b2-4cd2-ae93-39e398071c51" finished successfully.
You are now ready to push your docker image to the repo.
% docker push gcr.io/personal-ai-assistant-454604/personal-ai-assistant:v1
The push refers to repository [gcr.io/personal-ai-assistant-454604/personal-ai-assistant]
86176c83dbdf: Pushed
82cade0ba51d: Pushed
4f4fb700ef54: Layer already exists
6e0921a3c303: Pushed
f67f04ca5390: Pushed
da1cbe0d584f: Layer already exists
cec49b84de9d: Layer already exists
12308ec072b4: Pushed
50a1bda33068: Pushed
58ecaedd9062: Pushed
6e909acdb790: Layer already exists
14e45e94f512: Pushed
9a95d1744747: Layer already exists
v1: digest: sha256:5651aa3cc192ba7c3fc43a9eb40227da0dd7d621fe351be430a094c120ea33b8 size: 856
The image then can be pulled from anywhere now.
% docker pull --platform=linux/amd64 gcr.io/personal-ai-assistant-454604/personal-ai-assistant:v1
Digest: sha256:5651aa3cc192ba7c3fc43a9eb40227da0dd7d621fe351be430a094c120ea33b8
Status: Image is up to date for gcr.io/personal-ai-assistant-454604/personal-ai-assistant:v1
gcr.io/personal-ai-assistant-454604/personal-ai-assistant:v1
Now it is time to celebrate!