-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bc4435a
commit ebaba23
Showing
12 changed files
with
321 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
cloud-infrastructure/terraform/modules/kubernetes/hm_litellm_iam_role/main.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
terraform { | ||
required_providers { | ||
aws = { | ||
source = "hashicorp/aws" | ||
} | ||
} | ||
} | ||
|
||
locals { | ||
aws_iam_role_name_prefix = "LiteLLMRole" | ||
} | ||
# https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role | ||
resource "aws_iam_role" "hm_litellm_iam_role" { | ||
name = "${local.aws_iam_role_name_prefix}-${var.litellm_service_account_name}" | ||
assume_role_policy = jsonencode({ | ||
Version = "2012-10-17" | ||
Statement = [ | ||
{ | ||
Effect = "Allow" | ||
Principal = { | ||
Federated = var.amazon_eks_cluster_oidc_provider_arn | ||
} | ||
Action = "sts:AssumeRoleWithWebIdentity" | ||
Condition = { | ||
StringEquals = { | ||
"${var.amazon_eks_cluster_oidc_provider}:aud" = "sts.amazonaws.com", | ||
"${var.amazon_eks_cluster_oidc_provider}:sub" = "system:serviceaccount:${var.litellm_namespace}:${var.litellm_service_account_name}" | ||
} | ||
} | ||
} | ||
] | ||
}) | ||
tags = { | ||
Environment = var.environment | ||
Team = var.team | ||
Name = "${local.aws_iam_role_name_prefix}-${var.litellm_service_account_name}" | ||
} | ||
} | ||
# https://docs.aws.amazon.com/bedrock/latest/userguide/security_iam_id-based-policy-examples.html#security_iam_id-based-policy-examples-perform-actions-pt | ||
# https://docs.aws.amazon.com/bedrock/latest/userguide/model-ids.html | ||
# https://registry.terraform.io/providers/vancluever/acme/latest/docs/guides/dns-providers-route53#least-privilege-policy-for-production-purposes | ||
# https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy | ||
resource "aws_iam_role_policy" "hm_litellm_iam_role_policy" { | ||
name = "${local.aws_iam_role_name_prefix}Policy-${var.litellm_service_account_name}" | ||
role = aws_iam_role.hm_litellm_iam_role.name | ||
policy = jsonencode({ | ||
Version = "2012-10-17" | ||
Statement = [ | ||
{ | ||
Effect = "Allow" | ||
Action = [ | ||
"bedrock:InvokeModel", | ||
"bedrock:InvokeModelWithResponseStream" | ||
] | ||
Resource = [ | ||
# Claude Haiku | ||
"arn:aws:bedrock:*::foundation-model/anthropic.claude-3-5-haiku-20241022-v1:0", | ||
"arn:aws:bedrock:*::foundation-model/anthropic.claude-3-haiku-20240307-v1:0", | ||
# Claude Opus | ||
"arn:aws:bedrock:*::foundation-model/anthropic.claude-3-opus-20240229-v1:0", | ||
# Claude Sonnet | ||
"arn:aws:bedrock:*::foundation-model/anthropic.claude-3-5-sonnet-20241022-v2:0", | ||
"arn:aws:bedrock:*::foundation-model/anthropic.claude-3-5-sonnet-20240620-v1:0" | ||
] | ||
} | ||
] | ||
}) | ||
} |
18 changes: 18 additions & 0 deletions
18
cloud-infrastructure/terraform/modules/kubernetes/hm_litellm_iam_role/variables.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
variable "litellm_service_account_name" { | ||
type = string | ||
} | ||
variable "litellm_namespace" { | ||
type = string | ||
} | ||
variable "amazon_eks_cluster_oidc_provider" { | ||
type = string | ||
} | ||
variable "amazon_eks_cluster_oidc_provider_arn" { | ||
type = string | ||
} | ||
variable "environment" { | ||
type = string | ||
} | ||
variable "team" { | ||
type = string | ||
} |
6 changes: 6 additions & 0 deletions
6
kubernetes/argo-cd/applications/production-hm/litellm/Makefile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
argo-cd-app-create: | ||
argocd app create production-hm-litellm --file=manifests/hm-litellm-application.yaml | ||
argo-cd-app-update: | ||
argocd app create production-hm-litellm --file=manifests/hm-litellm-application.yaml --upsert | ||
argo-cd-app-delete: | ||
argocd app delete production-hm-litellm --yes |
22 changes: 22 additions & 0 deletions
22
.../argo-cd/applications/production-hm/litellm/argo-cd-manifests/hm-litellm-application.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
--- | ||
apiVersion: argoproj.io/v1alpha1 | ||
kind: Application | ||
metadata: | ||
name: production-hm-litellm | ||
namespace: production-hm-argo-cd | ||
labels: | ||
app.kubernetes.io/name: hm-litellm | ||
spec: | ||
project: production-hm | ||
source: | ||
repoURL: [email protected]:hongbo-miao/hongbomiao.com.git | ||
targetRevision: main | ||
path: kubernetes/argo-cd/applications/production-hm/litellm/kubernetes-manifests | ||
destination: | ||
namespace: production-hm-litellm | ||
server: https://kubernetes.default.svc | ||
syncPolicy: | ||
syncOptions: | ||
- ServerSideApply=true | ||
automated: | ||
prune: true |
30 changes: 30 additions & 0 deletions
30
...rgo-cd/applications/production-hm/litellm/kubernetes-manifests/hm-litellm-config-map.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
--- | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: hm-litellm-config-map | ||
namespace: production-hm-litellm | ||
annotations: | ||
# https://argo-cd.readthedocs.io/en/stable/user-guide/resource_hooks | ||
argocd.argoproj.io/hook: PreSync | ||
labels: | ||
app.kubernetes.io/name: hm-litellm-config-map | ||
app.kubernetes.io/part-of: production-hm-litellm | ||
data: | ||
config.yaml: | | ||
# https://docs.aws.amazon.com/bedrock/latest/userguide/model-ids.html | ||
model_list: | ||
# Claude Haiku | ||
- model_name: claude-3-5-haiku | ||
litellm_params: | ||
model: anthropic.claude-3-5-haiku-20241022-v1:0 | ||
# Claude Opus | ||
- model_name: claude-3-opus | ||
litellm_params: | ||
model: bedrock/anthropic.claude-3-opus-20240229-v1:0 | ||
# Claude Sonnet | ||
- model_name: claude-3-5-sonnet | ||
litellm_params: | ||
model: bedrock/anthropic.claude-3-5-sonnet-20241022-v2:0 | ||
litellm_settings: | ||
modify_params: True |
43 changes: 43 additions & 0 deletions
43
...rgo-cd/applications/production-hm/litellm/kubernetes-manifests/hm-litellm-deployment.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
--- | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: hm-litellm-deployment | ||
namespace: production-hm-litellm | ||
labels: | ||
app.kubernetes.io/name: hm-litellm-deployment | ||
app.kubernetes.io/part-of: production-hm-litellm | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
app: hm-litellm | ||
template: | ||
metadata: | ||
labels: | ||
app: hm-litellm | ||
spec: | ||
serviceAccountName: hm-litellm-service-account | ||
containers: | ||
- name: litellm | ||
image: ghcr.io/berriai/litellm:main-v1.52.3 | ||
ports: | ||
- name: litellm | ||
protocol: TCP | ||
containerPort: 4000 | ||
command: ["litellm", "--port", "4000", "--config", "/app/config.yaml", "--detailed_debug"] | ||
volumeMounts: | ||
- name: litellm-volume | ||
mountPath: /app/config.yaml | ||
subPath: config.yaml | ||
resources: | ||
requests: | ||
cpu: 50m | ||
memory: 512Mi | ||
limits: | ||
cpu: 100m | ||
memory: 1Gi | ||
volumes: | ||
- name: litellm-volume | ||
configMap: | ||
name: hm-litellm-config-map |
34 changes: 34 additions & 0 deletions
34
...s/argo-cd/applications/production-hm/litellm/kubernetes-manifests/hm-litellm-ingress.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
--- | ||
apiVersion: networking.k8s.io/v1 | ||
kind: Ingress | ||
metadata: | ||
name: hm-litellm-ingress | ||
namespace: production-hm-litellm | ||
annotations: | ||
kubernetes.io/ingress.class: traefik | ||
# https://doc.traefik.io/traefik/routing/providers/kubernetes-ingress/#on-ingress | ||
traefik.ingress.kubernetes.io/router.entrypoints: websecure | ||
traefik.ingress.kubernetes.io/router.tls: "true" | ||
# https://kubernetes-sigs.github.io/external-dns/latest/annotations/annotations | ||
external-dns.alpha.kubernetes.io/hostname: hm-litellm.internal.hongbomiao.com | ||
# https://argo-cd.readthedocs.io/en/stable/user-guide/resource_hooks | ||
argocd.argoproj.io/hook: PostSync | ||
labels: | ||
app.kubernetes.io/name: hm-litellm-ingress | ||
app.kubernetes.io/part-of: production-hm-litellm | ||
spec: | ||
rules: | ||
- host: hm-litellm.internal.hongbomiao.com | ||
http: | ||
paths: | ||
- path: / | ||
pathType: Prefix | ||
backend: | ||
service: | ||
name: hm-litellm-service | ||
port: | ||
number: 80 | ||
tls: | ||
- hosts: | ||
- hm-litellm.internal.hongbomiao.com | ||
secretName: production-hm-litellm-certificate |
12 changes: 12 additions & 0 deletions
12
...d/applications/production-hm/litellm/kubernetes-manifests/hm-litellm-service-account.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--- | ||
apiVersion: v1 | ||
kind: ServiceAccount | ||
metadata: | ||
name: hm-litellm-service-account | ||
namespace: production-hm-litellm | ||
annotations: | ||
# https://docs.aws.amazon.com/eks/latest/userguide/associate-service-account-role.html | ||
eks.amazonaws.com/role-arn: arn:aws:iam::272394222652:role/LiteLLMRole-hm-litellm-service-account | ||
labels: | ||
app.kubernetes.io/name: hm-litellm-service-account | ||
app.kubernetes.io/part-of: production-hm-litellm |
18 changes: 18 additions & 0 deletions
18
...s/argo-cd/applications/production-hm/litellm/kubernetes-manifests/hm-litellm-service.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
--- | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: hm-litellm-service | ||
namespace: production-hm-litellm | ||
labels: | ||
app.kubernetes.io/name: hm-litellm-service | ||
app.kubernetes.io/part-of: production-hm-litellm | ||
spec: | ||
type: ClusterIP | ||
selector: | ||
app: hm-litellm | ||
ports: | ||
- name: litellm | ||
protocol: TCP | ||
targetPort: litellm | ||
port: 80 |
23 changes: 23 additions & 0 deletions
23
...cations/production-hm/litellm/kubernetes-manifests/production-hm-litellm-certificate.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# https://cert-manager.io/docs/usage/certificate | ||
--- | ||
apiVersion: cert-manager.io/v1 | ||
kind: Certificate | ||
metadata: | ||
name: production-hm-litellm-certificate | ||
namespace: production-hm-litellm | ||
annotations: | ||
# https://argo-cd.readthedocs.io/en/stable/user-guide/resource_hooks | ||
argocd.argoproj.io/hook: PreSync | ||
spec: | ||
commonName: hm-litellm.internal.hongbomiao.com | ||
secretName: production-hm-litellm-certificate | ||
dnsNames: | ||
- hm-litellm.internal.hongbomiao.com | ||
issuerRef: | ||
kind: ClusterIssuer | ||
name: production-lets-encrypt-cluster-issuer | ||
# https://letsencrypt.org/certificates | ||
privateKey: | ||
algorithm: ECDSA | ||
size: 384 | ||
rotationPolicy: Always |
23 changes: 23 additions & 0 deletions
23
...plications/production-hm/litellm/kubernetes-manifests/staging-hm-litellm-certificate.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# https://cert-manager.io/docs/usage/certificate | ||
--- | ||
apiVersion: cert-manager.io/v1 | ||
kind: Certificate | ||
metadata: | ||
name: staging-hm-litellm-certificate | ||
namespace: production-hm-litellm | ||
annotations: | ||
# https://argo-cd.readthedocs.io/en/stable/user-guide/resource_hooks | ||
argocd.argoproj.io/hook: PreSync | ||
spec: | ||
commonName: hm-litellm.internal.hongbomiao.com | ||
secretName: staging-hm-litellm-certificate | ||
dnsNames: | ||
- hm-litellm.internal.hongbomiao.com | ||
issuerRef: | ||
kind: ClusterIssuer | ||
name: staging-lets-encrypt-cluster-issuer | ||
# https://letsencrypt.org/certificates | ||
privateKey: | ||
algorithm: ECDSA | ||
size: 384 | ||
rotationPolicy: Always |