K8s sandbox

From UVOO Tech Wiki
Revision as of 03:09, 10 October 2021 by Busk (talk | contribs)
Jump to navigation Jump to search

Example 1

https://kubernetes.io/docs/tasks/access-application-cluster/ingress-minikube/

kubectl create deployment web --image=gcr.io/google-samples/hello-app:1.0
kubectl expose deployment web --type=NodePort --port=8080
kubectl get service web

ingress.yml

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: example-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
  rules:
    - host: hello-world.info
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: web
                port:
                  number: 8080
kubectl apply -f ingress.yml
kubectl get ingress
curl -H "Host: hello-world.info" 10.x.x.y # k8s Cluster Node ip address

More Examples

apiVersion: apps/v1
kind: Deployment
metadata:
  name: testnginx-deployment
  namespace: test
spec:
  selector:
    matchLabels:
      app: testnginx
  replicas: 2
  template:
    metadata:
      labels:
        app: testnginx
    spec:
      containers:
      - name: nginx
        image: nginx:latest
        ports:
        - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: testnginx-service
spec:
  type: NodePort
  selector:
    app: testnginx
  ports:
      # By default and for convenience, the `targetPort` is set to the same value as the `port` field.
    - port: 80
      targetPort: 80
      # Optional field
      # By default and for convenience, the Kubernetes control plane will allocate a port from a range (default: 30000-32767)
      nodePort: 30007
curl -H "Host: cafe.example.com" http://127.0.0.1:30007

Refs

https://stackoverflow.com/questions/54506269/simple-ingress-from-host-with-microk8s

https://kubernetes.io/docs/tasks/access-application-cluster/ingress-minikube/