First workload¶
Deploy your first application to Playpen.
Prerequisites¶
- Playpen is installed (see Installation)
- All services are running and accessible
- Port forwarding is set up
Quick start¶
Deploy a simple Python Flask application:
1. Create application¶
Create a new directory and application files:
Create app.py:
from flask import Flask, jsonify
app = Flask(__name__)
@app.route('/')
def hello():
return jsonify({
"message": "Hello from Playpen!",
"status": "running"
})
@app.route('/health')
def health():
return jsonify({"status": "healthy"}), 200
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000)
Create requirements.txt:
Create Dockerfile:
FROM playpen/python-base:latest
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY app.py .
EXPOSE 5000
CMD ["python", "app.py"]
2. Build and test locally¶
# Build image
docker build -t my-first-app:latest .
# Run locally
docker run -p 5000:5000 my-first-app:latest
# Test
curl http://localhost:5000
3. Deploy to Kubernetes¶
Create deployment.yaml:
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-first-app
namespace: playpen-apps
spec:
replicas: 1
selector:
matchLabels:
app: my-first-app
template:
metadata:
labels:
app: my-first-app
spec:
containers:
- name: app
image: my-first-app:latest
ports:
- containerPort: 5000
---
apiVersion: v1
kind: Service
metadata:
name: my-first-app
namespace: playpen-apps
spec:
selector:
app: my-first-app
ports:
- port: 80
targetPort: 5000
Deploy:
kubectl apply -f deployment.yaml
# Wait for deployment
kubectl wait --for=condition=available deployment/my-first-app -n playpen-apps --timeout=120s
# Port forward
kubectl port-forward -n playpen-apps svc/my-first-app 5000:80
# Test
curl http://localhost:5000
Common workflows¶
Python web application¶
- Use base image:
playpen/python-baseincludes Flask, FastAPI, and common libraries - Build locally: Test your application with Docker
- Push to Nexus: Store images in Nexus Docker registry
- Deploy: Use Kubernetes deployments in
playpen-appsnamespace
Machine learning training¶
- Use ML runtime:
playpen/ml-runtimeincludes PyTorch, transformers, MLflow - Track experiments: Use MLflow for experiment tracking
- Save models: Store models in Nexus or persistent volumes
- Deploy inference: Create FastAPI service for model inference
CI/CD pipeline¶
- Create Jenkinsfile: Define your pipeline
- Use Kaniko agent: Build containers without Docker socket
- Publish artifacts: Push to Nexus repositories
- Auto-deploy: Deploy to Kubernetes on successful builds
Service integration examples¶
Using PostgreSQL¶
import psycopg2
import os
# Connect to PostgreSQL
conn = psycopg2.connect(
host=os.getenv("POSTGRES_HOST", "postgres.playpen-platform.svc.cluster.local"),
port=5432,
database=os.getenv("POSTGRES_DB", "playpen"),
user=os.getenv("POSTGRES_USER", "playpen"),
password=os.getenv("POSTGRES_PASSWORD")
)
# Use database
cursor = conn.cursor()
cursor.execute("CREATE TABLE IF NOT EXISTS users (id SERIAL PRIMARY KEY, name VARCHAR(255))")
conn.commit()
conn.close()
Using Nexus Maven repository¶
# Publish JAR artifact
curl -v \
-u username:password \
--upload-file my-app-1.0.0.jar \
http://nexus.playpen-platform.svc.cluster.local:8081/repository/maven-releases/com/playpen/my-app/1.0.0/my-app-1.0.0.jar
Using Dex OIDC¶
from authlib.integrations.flask_client import OAuth
oauth = OAuth()
oauth.register(
name='dex',
client_id=os.getenv('OIDC_CLIENT_ID'),
client_secret=os.getenv('OIDC_CLIENT_SECRET'),
server_metadata_url='http://dex.playpen-platform.svc.cluster.local:5556/dex/.well-known/openid-configuration',
client_kwargs={'scope': 'openid email profile'}
)
Next steps¶
- Explore platform guides for detailed workflows
- Learn about CI/CD automation
- Review best practices