kyma-project / api-gateway

Apache License 2.0
4 stars 27 forks source link

Add a step-by-step documentation to expose a workload locally using k3d #1133

Open abbi-gaurav opened 3 months ago

abbi-gaurav commented 3 months ago

Description

Technically advanced users like to try out kyma locally. Using k3d is the easiest way to do it. However, there is no clear step-by-step documentation. It is scattered, and some steps may be wrong.

e.g. this local domain is no longer used

If you are using k3d, add httpbin.kyma.local to the entry with k3d IP in your system’s /etc/hosts file.

I tried myself and was able to put together a set of steps. Thanks to @triffer for resolving one misconfiguration issue:

Steps

k3d cluster create kyma --kubeconfig-switch-context -p 30080:80@loadbalancer -p 30443:443@loadbalancer --k3s-arg "--disable=traefik@server:0"
kubectl create ns kyma-system
kubectl label namespace kyma-system istio-injection=enabled --overwrite
kubectl apply -f https://github.com/kyma-project/istio/releases/latest/download/istio-manager.yaml
kubectl apply -f https://github.com/kyma-project/istio/releases/latest/download/istio-default-cr.yaml
kubectl label namespace kyma-system istio-injection=enabled --overwrite
kubectl apply -f https://github.com/kyma-project/api-gateway/releases/latest/download/api-gateway-manager.yaml
kubectl apply -f https://github.com/kyma-project/api-gateway/releases/latest/download/apigateway-default-cr.yaml
cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: ConfigMap
metadata:
  name: coredns-custom
  namespace: kube-system
data:
  kyma.override: |
    rewrite name regex (.*)\.local\.kyma\.dev istio-ingressgateway.istio-system.svc.cluster.local
EOF

kubectl rollout restart deployment -n kube-system coredns
kubectl label namespace default istio-injection=enabled
kubectl create deployment nginx --image=nginx --port=80
kubectl expose deployment nginx
cat <<EOF | kubectl apply -f -
apiVersion: gateway.kyma-project.io/v1beta1
kind: APIRule
metadata:
  name: nginx
spec:
  gateway: kyma-system/kyma-gateway
  host: nginx
  rules:
  - accessStrategies:
    - handler: allow
    methods:
    - GET
    path: /.*
    service:
      name: nginx
      port: 80
status: {}
EOF
k get virtualservices.networking.istio.io
NAME          GATEWAYS                       HOSTS                      AGE
nginx-p5mhw   ["kyma-system/kyma-gateway"]   ["nginx.local.kyma.dev"]   24h
127.0.0.1 nginx.local.kyma.dev
curl https://nginx.local.kyma.dev:30443 -k -v
Darshan-Movilitas commented 3 months ago

This works fine. Thank you

nataliasitko commented 2 months ago

We have a similar flow already: Quick Install --> Create a Workload --> Expose a Workload that uses HTTPBin instead of nginx and should work on both k3d and Gardener. I’ll be working on the tutorials as part of this issue so they’re more straightforward also for developers who’d like to install API Gateway locally

The Quick Install guide should be the entry point for all Kyma tutorials that you can see on the kyma-project website, so I'd like to update the k3d cluster create... command there.

@abbi-gaurav @triffer I have a few questions regarding the steps:

mmitoraj commented 1 month ago

@abbi-gaurav, could you have a look at the above comment, please?

abbi-gaurav commented 3 weeks ago

I think steps core DNS update are required. Regarding ports, it is not a must to use these ports. They can be some other ports. Since we are talking about running kyma locally, we need to use ports that are not reserved.

strekm commented 3 weeks ago

@nataliasitko @mmitoraj in quick install we have slightly different command:

`k3d cluster create --k3s-arg ‘--tls-san=host.docker.internal@server:*’
kubectl create ns kyma-system`

while in the issue:

k3d cluster create kyma --kubeconfig-switch-context -p 30080:80@loadbalancer -p 30443:443@loadbalancer --k3s-arg "--disable=traefik@server:0"
kubectl create ns kyma-system

this needs to be adjusted in quick install

nataliasitko commented 1 week ago

I've updated the command, added the step to update CoreDNS, and added a note about the ports. It's approved by Goats. @abbi-gaurav Could you also see if it's fine with you? Here's the PR: https://github.com/kyma-project/kyma/pull/18749/files