K8s/Run: Difference between revisions
Jump to navigation
Jump to search
(→Apply) |
|||
Line 68: | Line 68: | ||
==Apply== | ==Apply== | ||
===Apply » Infinity=== | |||
{| | |||
| valign="top" | | |||
<syntaxhighlight lang="bash"> | |||
kubectl -n swiss-knife get pvc swiss-knife-${USER}-pvc | |||
kubectl -n swiss-knife get pv swiss-knife-${USER}-pv | |||
kubectl get pv swiss-knife-${USER}-pv | |||
</syntaxhighlight> | |||
---- | |||
<syntaxhighlight lang="bash"> | |||
kubectl -n swiss-knife run infinity --image=alpine --overrides="$(cat <<-'JSON' | |||
{ "apiVersion": "v1", | |||
"spec": { | |||
"volumes": [{ | |||
"name": "data", | |||
"persistentVolumeClaim": | |||
{"claimName": "swiss-knife-${USER}-pvc"}}], | |||
"containers": [{ | |||
"name": "psql", | |||
"image": "alpine", | |||
"volumeMounts": [{ | |||
"name": "data", | |||
"mountPath": "/opt/psql"}]}]}} | |||
JSON | |||
)" -- sleep infinity | |||
</syntaxhighlight> | |||
---- | |||
<syntaxhighlight lang="bash"> | |||
kubectl -n swiss-knife delete pvc swiss-knife-${USER}-pvc | |||
kubectl -n swiss-knife delete pv swiss-knife-${USER}-pv | |||
kubectl delete pv swiss-knife-${USER}-pv | |||
</syntaxhighlight> | |||
| valign="top" | | |||
<syntaxhighlight lang="yaml"> | <syntaxhighlight lang="yaml"> | ||
cat << YML | kubectl apply -f - | cat << YML | kubectl apply -f - | ||
Line 112: | Line 146: | ||
YML | YML | ||
</syntaxhighlight> | </syntaxhighlight> | ||
|} | |||
==Playground== | ==Playground== |
Revision as of 00:30, 27 August 2024
export KUBECONFIG="${HOME}/.kube/lke-dev-kubeconfig.yaml"
export KUBECONFIG="${HOME}/.kube/gke-uat-kubeconfig.yaml"
export KUBECONFIG="${HOME}/.kube/eks-pro-kubeconfig.yaml"
|
export KUBECONFIG="${HOME}/.kube/config"
kubectl config get-contexts
kubectl cluster-info
|
kubectl get ns|grep swiss-knife
kubectl delete ns swiss-knife
kubectl create ns swiss-knife
|
Run
Run » PSQL
kubectl -n swiss-knife run -i --tty --rm psql --image=alpine --restart=Never -- sh
echo -n password: ;read -s PGPASSWORD;export PGPASSWORD
apk --update add postgresql-client inetutils-telnet
psql -d postgres -U postgres -h postgresql.postgresql
Run » Infinity
kubectl -n swiss-knife run infinity --image=alpine -- sleep infinity
kubectl -n swiss-knife exec -it infinity -- sh
apk --update add inetutils-telnet
Run » Redis CLI
kubectl -n swiss-knife run -i --tty --rm redis-cli --image=alpine --restart=Never -- sh
echo -n password: ;read -s REDISCLI_AUTH;export REDISCLI_AUTH;echo
apk --update add redis inetutils-telnet
echo 'ping'|redis-cli -h redis-headless.redis
Run » MinIO CLI
kubectl -n swiss-knife run -i --tty --rm minio-cli --image=alpine --restart=Never -- sh
apk --update add minio-client inetutils-telnet
echo -n password: ;\
read -s MINIO_SERVER_ROOT_PASSWORD;\
export MINIO_SERVER_ROOT_PASSWORD;\
export MINIO_SERVER_ROOT_USER=admin;\
export MINIO_SERVER_HOST=minio.k8s.local;echo
mcli ping --error-count 5 minio.minio
mcli ping --count 5 minio.minio
telnet minio.minio 9000
telnet minio.minio 9001
Apply
Apply » Infinity
kubectl -n swiss-knife get pvc swiss-knife-${USER}-pvc
kubectl -n swiss-knife get pv swiss-knife-${USER}-pv
kubectl get pv swiss-knife-${USER}-pv
kubectl -n swiss-knife run infinity --image=alpine --overrides="$(cat <<-'JSON'
{ "apiVersion": "v1",
"spec": {
"volumes": [{
"name": "data",
"persistentVolumeClaim":
{"claimName": "swiss-knife-${USER}-pvc"}}],
"containers": [{
"name": "psql",
"image": "alpine",
"volumeMounts": [{
"name": "data",
"mountPath": "/opt/psql"}]}]}}
JSON
)" -- sleep infinity
kubectl -n swiss-knife delete pvc swiss-knife-${USER}-pvc
kubectl -n swiss-knife delete pv swiss-knife-${USER}-pv
kubectl delete pv swiss-knife-${USER}-pv
|
cat << YML | kubectl apply -f -
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: swiss-knife-${USER}-pv
annotations:
pv.kubernetes.io/provisioned-by: k8s.io/minikube-hostpath
spec:
capacity:
storage: 10Gi
hostPath:
path: /tmp/hostpath-provisioner/swiss-knife/data-${USER}-pv
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Delete
storageClassName: standard
volumeMode: Filesystem
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: swiss-knife-${USER}-pvc
namespace: swiss-knife
labels:
app.kubernetes.io/component: primary
app.kubernetes.io/instance: infinity
app.kubernetes.io/name: infinity
annotations:
volume.beta.kubernetes.io/storage-provisioner: k8s.io/minikube-hostpath
volume.kubernetes.io/storage-provisioner: k8s.io/minikube-hostpath
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
volumeName: swiss-knife-${USER}-pv
storageClassName: standard
volumeMode: Filesystem
---
YML
|
Playground
kubectl -n swiss-knife delete pods minio-cli
kubectl -n swiss-knife delete pods redis-cli
|
kubectl -n swiss-knife delete pods infinity
kubectl -n swiss-knife delete pods psql
|
kubectl -n swiss-knife run infinity --image=alpine -- sleep infinity
kubectl -n swiss-knife run ubuntu --image=ubuntu -- sleep infinity
|
|
| |||
References
| ||