Created
July 30, 2024 18:22
-
-
Save suhovius/37accd30d2aac0c1ea8f4851b27e33d0 to your computer and use it in GitHub Desktop.
Ollama + Kubernetes Experiments
This file contains hidden or 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
ollama run llama3 | |
>>> create app pod labeled 'app=demo, run=demo' with container image 'gcr.io/k8s-k3s/demo:v1.0.0' named 'app' and open container port 8000 with name 'http' | |
Here is the YAML file to create an App of Pod labeled 'app=demo, run=demo' with a container image 'gcr.io/k8s-k3s/demo:v1.0.0', named 'app', and opening container port 8000 with name | |
'http': | |
```yaml | |
apiVersion: apps/v1 | |
kind: Deployment | |
metadata: | |
labels: | |
app: demo | |
run: demo | |
spec: | |
replicas: 1 | |
selector: | |
matchLabels: | |
app: demo | |
template: | |
metadata: | |
labels: | |
app: demo | |
spec: | |
containers: | |
- name: http | |
image: gcr.io/k8s-k3s/demo:v1.0.0 | |
ports: | |
- containerPort: 8000 | |
name: http | |
``` | |
Let me explain what each part of the YAML file does: | |
* `apiVersion` and `kind`: We're defining a Deployment, which is a type of Kubernetes object. | |
* `metadata`: This section defines metadata about the Deployment, such as labels. In this case, we're setting two labels: `app=demo` and `run=demo`. | |
* `spec`: This section defines the desired state of the Deployment. We're specifying: | |
+ `replicas`: The number of replicas (i.e., instances) of the container to run. In this case, we want only one instance. | |
+ `selector`: A selector that matches the pods created by this Deployment. We're setting it to match the label `app=demo`. | |
+ `template`: This is a template for the containers in the pod. We're defining: | |
- `metadata`: More metadata about the container, including labels. | |
- `spec`: The specifications for the container. In this case, we're specifying: | |
- `containers`: A list of containers to run. We're defining one container with: | |
+ `name`: The name of the container, set to `http`. | |
+ `image`: The container image, set to `gcr.io/k8s-k3s/demo:v1.0.0`. | |
+ `ports`: A list of ports opened by the container. We're defining one port: | |
- `containerPort`: The port number (8000) and name (`http`) for this port. | |
To create this Deployment, you can use the `kubectl apply` command with the YAML file as input: | |
```bash | |
kubectl apply -f deployment.yaml | |
``` | |
Replace `deployment.yaml` with the name of your YAML file. | |
>>> create app-volume pod with container image 'gcr.io/kuar-demo/kuard-amd64:1' named 'app' and open container port 8080 with name 'http' with livenessProbe http get at port 8080 with settin | |
... gs: initial delay seconds 5, timeout seconds 1, period seconds 10, failure threshold 3 and readinessProbe at path /ready port 8080 with settings: period seconds 2, initial delay seconds | |
... 0, failure threshold 3, success threshold 1. Add volume mount named 'data' at host path /var/lib/app to mounted at /data | |
Here is the YAML file to create an App of Pod labeled 'app=demo, run=demo' with a container image 'gcr.io/kuar-demo/kuard-amd64:1', named 'app', and opening container port 8080 with | |
name 'http' with livenessProbe http get at port 8080 with settings: initial delay seconds 5, timeout seconds 1, period seconds 10, failure threshold 3 and readinessProbe at path /ready | |
port 8080 with settings: period seconds 2, initial delay seconds 0, failure threshold 3, success threshold 1. Add volume mount named 'data' at host path /var/lib/app to mounted at | |
/data: | |
```yaml | |
apiVersion: v1 | |
kind: Pod | |
metadata: | |
labels: | |
app: demo | |
spec: | |
containers: | |
- name: app | |
image: gcr.io/kuar-demo/kuard-amd64:1 | |
ports: | |
- containerPort: 8080 | |
name: http | |
volumeMounts: | |
- name: data | |
mountPath: /data | |
readOnly: false | |
probes: | |
- type: HTTPGet | |
httpGet: | |
path: /ready | |
port: 8080 | |
initialDelaySeconds: 5 | |
timeoutSeconds: 1 | |
periodSeconds: 10 | |
failureThreshold: 3 | |
livenessProbe: | |
type: HTTPGet | |
httpGet: | |
path: / | |
port: 8080 | |
initialDelaySeconds: 5 | |
timeoutSeconds: 1 | |
periodSeconds: 10 | |
failureThreshold: 3 | |
volumes: | |
- name: data | |
hostPath: | |
path: /var/lib/app | |
``` | |
Let me explain what each part of the YAML file does: | |
* `apiVersion` and `kind`: We're defining a Pod, which is a type of Kubernetes object. | |
* `metadata`: This section defines metadata about the Pod, such as labels. In this case, we're setting one label: `app=demo`. | |
* `spec`: This section defines the desired state of the Pod. We're specifying: | |
+ `containers`: A list of containers to run. We're defining one container with: | |
- `name`: The name of the container, set to `app`. | |
- `image`: The container image, set to `gcr.io/kuar-demo/kuard-amd64:1`. | |
- `ports`: A list of ports opened by the container. We're defining one port: | |
- `containerPort`: The port number (8080) and name (`http`) for this port. | |
+ `volumeMounts`: A list of volume mounts to attach to the container. We're defining one volume mount: | |
- `name`: The name of the volume, set to `data`. | |
- `mountPath`: The path in the container where we want to mount the volume, set to `/data`. | |
- `readOnly`: A boolean indicating whether the volume should be mounted read-only. We're setting it to `false`, which means the volume will be mounted read-write. | |
+ `probes`: A list of probes that can be used to check if a container is healthy. We're defining two probes: | |
- `livenessProbe`: A probe that checks if the container is running and responding to requests. It's an HTTPGet probe with settings: | |
- `type`: The type of probe, set to `HTTPGet`. | |
- `httpGet`: The details of the HTTP request, including the path (`/`) and port (8080). We're setting the initial delay to 5 seconds, the timeout to 1 second, and the period to 10 | |
seconds. We're also setting a failure threshold of 3. | |
- `readinessProbe`: A probe that checks if the container is ready to receive requests. It's an HTTPGet probe with settings: | |
- `type`: The type of probe, set to `HTTPGet`. | |
- `httpGet`: The details of the HTTP request, including the path (`/ready`) and port (8080). We're setting the period to 2 seconds, the initial delay to 0 seconds, a failure threshold | |
of 3, and a success threshold of 1. | |
* `volumes`: A list of volumes that can be used by the Pod. We're defining one volume: | |
- `name`: The name of the volume, set to `data`. | |
- `hostPath`: The details of the host path where we want to mount the volume, including the path `/var/lib/app`. | |
To create this Pod, you can use the `kubectl apply` command with the YAML file as input: | |
```bash | |
kubectl apply -f pod.yaml | |
``` | |
Replace `pod.yaml` with the name of your YAML file. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment