K8s/Run: Difference between revisions

From Chorke Wiki
Jump to navigation Jump to search
 
(21 intermediate revisions by the same user not shown)
Line 54: Line 54:
apk --update add minio-client inetutils-telnet
apk --update add minio-client inetutils-telnet


echo -n password: ;\
mcli alias set  k8s_gitlab_aa http://minio.minio:9000 Tnen3kCv71osfJKkhcIP rxMU6fWayQD6no1p1LO7orBmxNMtbKuyHITpflBJ
read -s MINIO_SERVER_ROOT_PASSWORD;\
mcli admin info k8s_gitlab_aa
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 alias set  k8s_gitlab_ab http://minio.minio:9000 FfG564tLdSlgaM2t0ig0 FEbThROKMZ06Feddr1SUMk85g4wRM5NZnVVrS24V
mcli ping --count 5 minio.minio
mcli admin info k8s_gitlab_ab


telnet minio.minio 9000
mcli alias set  s3_host_ab http://s3.host.k8s.local O2PLF0Pznp12HNbT9FbJ YIISq1Srxf9gv24fxkryN5ilQDg8P5wxJXt1qgle
telnet minio.minio 9001
mcli admin info s3_host_ab
</syntaxhighlight>


==Apply==
mcli alias set  s3_host_aa http://s3.host.k8s.local 6zXMWye9rOjKgpka pHKjpqiXK4RLpvdyX7qYuwbIk5KAkKa6
===Apply » Minikube » ${USER}===
mcli admin info s3_host_aa
{|
| valign="top" |
<syntaxhighlight lang="yaml">
cat << YML | kubectl -n swiss-knife apply -f -
---
apiVersion: v1
kind: Service
metadata:
  name: swiss-knife-${USER}
spec:
  ports:
  - port: 80
  selector:
    app: swiss-knife-${USER}
  clusterIP: None
YML
</syntaxhighlight>
----
<syntaxhighlight lang="bash">
kubectl -n swiss-knife exec -it    svc/swiss-knife-${USER} -c nginx -- sh
kubectl -n swiss-knife exec -it    svc/swiss-knife-${USER} -- sh
</syntaxhighlight>
----
<syntaxhighlight lang="bash">
kubectl -n swiss-knife port-forward svc/swiss-knife-${USER} 1980:80
kubectl -n swiss-knife port-forward svc/swiss-knife-${USER}    :80
</syntaxhighlight>
----
<syntaxhighlight lang="bash">
kubectl -n swiss-knife delete deploy    swiss-knife-${USER}
kubectl -n swiss-knife delete svc      swiss-knife-${USER}
kubectl -n swiss-knife delete pvc      swiss-knife-${USER}-pvc
</syntaxhighlight>


| valign="top" |
mcli alias set  k8s_admin http://minio.minio:9000 admin sadaqah!
<syntaxhighlight lang="yaml">
mcli admin info k8s_admin
cat << YML | kubectl -n swiss-knife apply -f -
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: swiss-knife-${USER}-pvc
spec:
  storageClassName: standard
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: swiss-knife-${USER}
spec:
  selector:
    matchLabels:
      app: swiss-knife-${USER}
  replicas: 1
  template:
    metadata:
      labels:
        app: swiss-knife-${USER}
    spec:
      containers:
      - name: nginx
        image: nginx:1.27-alpine
        ports:
        - containerPort: 80
        volumeMounts:
          - mountPath: /opt/swiss-knife/${USER}
            name: ${USER}-data
      volumes:
        - name: ${USER}-data
          persistentVolumeClaim:
            claimName: swiss-knife-${USER}-pvc
      restartPolicy: Always
YML
</syntaxhighlight>
</syntaxhighlight>
|}
----
===Apply » Minikube » Infinity===
{|
| valign="top" |
<syntaxhighlight lang="bash">
kubectl -n swiss-knife get pvc swiss-knife-${USER}-pvc
kubectl                get pv  swiss-knife-${USER}-pv
</syntaxhighlight>
----
<syntaxhighlight lang="bash">
kubectl -n swiss-knife delete pods infinity
</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": "infinity",
      "image": "alpine",
      "volumeMounts": [{
          "name": "data",
          "mountPath": "/opt/data-${USER}"}]}]}}
JSON
)" -- sleep infinity
</syntaxhighlight>
----
<syntaxhighlight lang="bash">
kubectl -n swiss-knife delete pvc swiss-knife-${USER}-pvc
kubectl                delete pv  swiss-knife-${USER}-pv
</syntaxhighlight>
| valign="top" |
<syntaxhighlight lang="yaml">
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}
  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
</syntaxhighlight>
|}


==Playground==
==Playground==
Line 308: Line 144:


| valign="top" |
| valign="top" |
* [https://stackoverflow.com/questions/31870222  K8s » <code>kubectl run</code> » <code>sleep infinity</code>]
* [https://stackoverflow.com/questions/71043168/ K8s » Attache a Volume to Pod Container]
* [https://stackoverflow.com/questions/71043168/ K8s » Attache a Volume to Pod Container]
* [https://stackoverflow.com/questions/23929235/ Bash » Multi-line String With Indentation]
* [https://stackoverflow.com/questions/23929235/ Bash » Multi-line String With Indentation]
* [https://kubernetes.io/docs/reference/kubectl/generated/kubectl_rollout/ K8s » <code>kubectl rollout</code>]
* [https://kubernetes.io/docs/reference/kubectl/generated/kubectl_rollout/ K8s » <code>kubectl rollout</code>]
* [[K8s/CSI Hostpath Driver|K8s » CSI Hostpath Driver]]
* [[K8s/CSI Hostpath Driver|K8s » CSI Hostpath Driver]]
* [[K8s/Swiss Knife|K8s » Swiss Knife]]
* [[K8s/Ingress|K8s » Ingress]]
* [[K8s/Ingress|K8s » Ingress]]
* [[K8s/Service|K8s » Service]]
* [[MinIO]]
* [[MinIO]]
* [[CIDR]]
* [[CIDR]]
Line 320: Line 156:


| valign="top" |
| valign="top" |
* [https://stackoverflow.com/questions/31870222  K8s » <code>kubectl run</code> » <code>sleep infinity</code>]


|}
|}

Latest revision as of 09:30, 7 September 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;echo
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

mcli alias set  k8s_gitlab_aa http://minio.minio:9000 Tnen3kCv71osfJKkhcIP rxMU6fWayQD6no1p1LO7orBmxNMtbKuyHITpflBJ
mcli admin info k8s_gitlab_aa

mcli alias set  k8s_gitlab_ab http://minio.minio:9000 FfG564tLdSlgaM2t0ig0 FEbThROKMZ06Feddr1SUMk85g4wRM5NZnVVrS24V
mcli admin info k8s_gitlab_ab

mcli alias set  s3_host_ab http://s3.host.k8s.local O2PLF0Pznp12HNbT9FbJ YIISq1Srxf9gv24fxkryN5ilQDg8P5wxJXt1qgle
mcli admin info s3_host_ab

mcli alias set  s3_host_aa http://s3.host.k8s.local 6zXMWye9rOjKgpka pHKjpqiXK4RLpvdyX7qYuwbIk5KAkKa6
mcli admin info s3_host_aa

mcli alias set  k8s_admin http://minio.minio:9000 admin sadaqah!
mcli admin info k8s_admin

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