GithubHelp home page GithubHelp logo

esc2024's Introduction

Kubernetes

On docker-desktop enable Kubernetes.

Setup docker-dashboard

Source

Create admin-user

Add the admin-user and bind to a predefined cluster role called cluster-admin.

apiVersion: v1
kind: ServiceAccount
metadata:
  name: admin-user
  namespace: kubernetes-dashboard

---

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: admin-user
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: cluster-admin
subjects:
  - kind: ServiceAccount
    name: admin-user
    namespace: kubernetes-dashboard

Deploy resources

Then instruct kubernetes to deploy.

> kubectl apply -f C:\Users\alme\source\repos\camp-2024\kubernetes-dashboard.yaml

> kubectl proxy

Create token

> kubectl -n kubernetes-dashboard create token admin-user

Open the kubernetes dashboard: http://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/#/deployment?namespace=_all

Delete deployments

kubectl delete -f C:\Users\alme\source\repos\camp-2024\kubernetes-dashboard.yaml

or

> kubectl get all -A
...
> kubectl -n kubernetes-dashboard delete deploy dashboard-metrics-scraper
> kubectl -n kubernetes-dashboard delete deploy kubernetes-dashboard

Volume mounts

Source:

Mount a windows folder

Create a persistant volume

In order to access a folder on the windows computer you need to know how docker mounts the windows host file system. Docker daemon mounts it in its /run/desktop/mnt/host/ directory. From there you can go /run/desktop/mnt/host/wsl or /run/desktop/mnt/host/c.

Persistent volumes are not names spaced. You can check that with kubectl api-resources --namespaced=false.

apiVersion: v1
kind: PersistentVolume
metadata:
  name: docker-registry-pv
spec:
  capacity:
    storage: 10Gi
  volumeMode: Filesystem
  accessModes:
    - ReadWriteOnce
  persistentVolumeReclaimPolicy: Delete
  storageClassName: hostpath
  local:
    path: /run/desktop/mnt/host/c/docker-registry
  nodeAffinity:
    required:
      nodeSelectorTerms:
        - matchExpressions:
            - key: kubernetes.io/hostname
              operator: In
              values:
                - docker-desktop

Storage classes

> kubectl get sc

NAME                 PROVISIONER
hostpath (default)   docker.io/hostpath

Create persistant volume claim

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: docker-registry-pvc
  namespace: docker-registry
spec:
  storageClassName: hostpath
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi

Create a pod

Mount C:/docker-registry as /usr/share/nginx/html.

apiVersion: v1
kind: Pod
metadata:
  name: docker-registry-pod
  namespace: docker-registry
spec:
  volumes:
    - name: docker-registry-pv
      persistentVolumeClaim:
        claimName: docker-registry-pvc
  containers:
    - name: docker-registry-container
      image: nginx
      ports:
        - containerPort: 80
          name: "http-server"
      volumeMounts:
        - mountPath: "/usr/share/nginx/html"
          name: docker-registry-pv

Now we can access the pod with the following command:

> kubectl exec -it docker-registry-pod -n docker-registry -- /bin/bash

root@docker-registry-pod:/# cat usr/share/nginx/html/index.html
Hello World!

I created the index.html file under C:/docker-registry.

Deploy .NET application docker image

Run a docker registry locally.

> docker run -d -p 5000:5000 --restart always --name registry registry:2

Build, tag and push image

> docker build -t localhost:5000/web-app -f Dockerfile .
> docker run -p 8080:8080 web-app

Run the container in a kubernetes pod.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: web-application-demo
  namespace: web-app
spec:
  replicas: 1
  selector:
    matchLabels:
      app: web-application-demo
  template:
    metadata:
      labels:
        app: web-application-demo
    spec:
      containers:
      - name: web-application-demo
        image: localhost:5000/web-app
        ports:
        - containerPort: 8080

---

apiVersion: v1
kind: Service
metadata:
  name: web-application-demo-service
  namespace: web-app
spec:
  selector:
    app: web-application-demo
  ports:
  - protocol: TCP
    port: 8080
    targetPort: 8080
    nodePort: 30000
  type: NodePort

Open: http://localhost:30000/weatherforecast

esc2024's People

Stargazers

Alan Keller avatar

Watchers

Alan Keller avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.