Skip to content

Instantly share code, notes, and snippets.

@v5tech
Created January 4, 2023 05:55
Show Gist options
  • Save v5tech/2c9ba54fa645b8e55a44ba9a6dc45c73 to your computer and use it in GitHub Desktop.
Save v5tech/2c9ba54fa645b8e55a44ba9a6dc45c73 to your computer and use it in GitHub Desktop.
Kubernetes Tips | Using scripts inside configmaps https://itnext.io/kubernetes-tips-using-scripts-inside-configmaps-9df03e17ac35
apiVersion: v1
kind: ConfigMap
metadata:
name: slim-shady-configmap
data:
slim-shady.sh: |
#!/bin/bash
echo "Hi!"
echo "My name is"
echo "What?"
echo "My name is"
echo "Who?"
echo "My name is"
echo "Chika-chika"
echo "Slim Shady"
---
apiVersion: batch/v1
kind: Job
metadata:
name: chicka-chicka-slim-shady
spec:
template:
spec:
containers:
- name: shady
image: centos
command: ["/script/slim-shady.sh"]
volumeMounts:
- name: script
mountPath: "/script"
volumes:
- name: script
configMap:
name: slim-shady-configmap
defaultMode: 0500
restartPolicy: Never
apiVersion: v1
kind: ConfigMap
metadata:
name: promote-model
data:
promote_model.py: |
"""
This file is used to demonstrate how to promote the latest version of a Model to "Production" stage so that it can be
served out of the Model Registry.
"""
import os
import mlflow
from mlflow.tracking import MlflowClient
# Set the Remote Tracking Server Information
mlflow.set_tracking_uri("http://mlflow")
# Promote the latest Version of Staging to Production
client = MlflowClient()
model_name = os.getenv("MODEL_NAME")
# Get the latest version in Stage "Staging" and promote to "Production"
models = client.get_latest_versions(model_name, stages=["Staging"])
for model in models:
name = model.name
latest_version = int(model.version)
run_id = model.run_id
current_stage = model.current_stage
print(name, latest_version)
# Transition
client.transition_model_version_stage(
name=name,
version=latest_version,
stage="Production"
)
---
apiVersion: batch/v1
kind: Job
metadata:
name: promote-model-a
spec:
template:
spec:
containers:
- name: promote
image: wbassler/mlflow-utils:0.0.1
command:
- python
args:
- /mlflow/promote.py
env:
- name: MODEL_NAME
value: model-a
volumeMounts:
- name: promote
mountPath: "/mlflow"
volumes:
- name: promote
configMap:
name: promote-model
defaultMode: 0500
restartPolicy: Never
apiVersion: v1
kind: ConfigMap
metadata:
name: create-users-dir
data:
users.ini: |
user1
user2
user3
user5
create-dir.sh: |
#!/bin/bash
set -ex
cat /scripts/users.ini | while read line
do
mkdir -pv /nfs/folder/$line
done
---
apiVersion: v1
kind: Pod
metadata:
generateName: create-users-dirs
spec:
containers:
- name: create-users
image: centos
command: ["/scripts/create-dir.sh"]
volumeMounts:
- name: script
mountPath: "/scripts"
volumes:
- name: script
configMap:
name: create-users-dir
defaultMode: 0500
items:
- key: create-dir.sh
path: create-dir.sh
- key: users.ini
path: users.ini
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment