Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to expose the server at a subpath behind Kubernetes ingress in version 2 #975

Closed
yuha0 opened this issue Sep 13, 2019 · 14 comments
Closed

Comments

@yuha0
Copy link

yuha0 commented Sep 13, 2019

Description

I am running the code server version 2 (docker image: codercom/code-server:2.1472-vsc1.38.1) in Kubernetes and need to access it at https://example.com/code, which is controlled by an Ingress Controller. I notice that there's a --base-path option in the command line argument but it is not working for me.

The Kubernetes manifest:

apiVersion: v1
kind: Service
metadata:
  name: code-server
spec:
  ports:
  - port: 8080
    name: http
    protocol: TCP
  selector:
    app: code-server
---
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: code-server
  name: code-server
spec:
  selector:
    matchLabels:
      app: code-server
  replicas: 1
  template:
    metadata:
      labels:
        app: code-server
    spec:
      containers:
      - image: codercom/code-server:2.1472-vsc1.38.1
        name: code-servery
        args:
        - --no-auth
        - --disable-telemetry
        - --allow-http
        - --log debug
        - --base-path https://example.com/code
---
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: code-server
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: "/$2"
spec:
  tls:
  - hosts:
    - example.com
  rules:
  - host: example.com
    http:
      paths:
      - backend:
          serviceName: code-server
          servicePort: 8080
        path: /code(/|$)(.*)

Related Issues

#241

@yuha0 yuha0 added the question label Sep 13, 2019
@sr229
Copy link
Contributor

sr229 commented Sep 13, 2019

@yuha0 I am against using a non-v1 Resource because non-v1 resources are not guranteed to be in most Kubernetes distributions. I don't think we can document this if that's the case due to the beta nature of the Ingress. However, I think we can document a LoadBalancer Resource instead.

@yuha0
Copy link
Author

yuha0 commented Sep 13, 2019

@sr229 Hi, I understand that beta API can change over time. But Ingress resources only have beta APIs (networking.k8s.io/v1beta1, or extensions/v1beta1 in old cluster versions), and that pretty much covers all Kubernetes users. If one wants to write a documentation to help any Kubernetes users at all, it has to be written with beta APIs.

IMHO, a LB example will help fewer users and the majority will not want to use a LB to expose code server: 1. Cloud providers charge users for each LB so it is very common to only have one LB pointing to a ingress controller. 2. LB is hard to setup in bare-metal environments.

Anyway, I think I can rephrase my question because it does not necessarily have to be related to Kubernetes at all. It is just that Kubernetes happens to be my deployment environment. Could you help answer:

How to expose code server version 2 at a subpath behind a reverse-proxy like NGINX?

@sr229
Copy link
Contributor

sr229 commented Sep 14, 2019

@sr229 Hi, I understand that beta API can change over time. But Ingress resources only have beta APIs (networking.k8s.io/v1beta1, or extensions/v1beta1 in old cluster versions), and that pretty much covers all Kubernetes users. If one wants to write a documentation to help any Kubernetes users at all, it has to be written with beta APIs.

IMHO, a LB example will help fewer users and the majority will not want to use a LB to expose code server: 1. Cloud providers charge users for each LB so it is very common to only have one LB pointing to a ingress controller. 2. LB is hard to setup in bare-metal environments.

Anyway, I think I can rephrase my question because it does not necessarily have to be related to Kubernetes at all. It is just that Kubernetes happens to be my deployment environment. Could you help answer:

How to expose code server version 2 at a subpath behind a reverse-proxy like NGINX?

v2 allows you to set a base path, we documented in the CLI but I think we should document that. As for ingresses, I think we would document it but as much as possible I want to document v1 resources to prevent further hiccups later on doc-wise

@code-asher
Copy link
Member

code-asher commented Sep 17, 2019

@yuha0 There's an example here using Nginx to host at a sub-path: https://github.com/cdr/code-server/blob/master/doc/quickstart.md#nginx-reverse-proxy.

FYI the base path option is only used to redirect properly from the login page (if using password authentication) and to set the Service-Allowed-Worker header value to the base path.

Let me know if that doesn't answer your question!

@code-asher
Copy link
Member

Also the base path should only be the path so: --base-path /code.

@cheoalfredo
Copy link

@yuha0 There's an example here using Nginx to host at a sub-path: https://github.com/cdr/code-server/blob/master/doc/quickstart.md#nginx-reverse-proxy.

FYI the base path option is only used to redirect properly from the login page (if using password authentication) and to set the Service-Allowed-Worker header value to the base path.

Let me know if that doesn't answer your question!

dude, i could not find that example, it throws a 404

@nhooyr
Copy link
Contributor

nhooyr commented Jun 10, 2020

This is a very old issue and the docs have been changed. These days we recommend caddy.

See https://github.com/cdr/code-server/blob/master/doc/guide.md

@cheoalfredo
Copy link

This is a very old issue and the docs have been changed. These days we recommend caddy.

See https://github.com/cdr/code-server/blob/master/doc/guide.md

thanks for the quick reply, so i ended up doing it with the ingress alone, just had to add the annotations nginx.ingress.kubernetes.io/rewrite-target, nginx.ingress.kubernetes.io/app-root and setting the path to /{subpath}(/|$)(.*) and it just worked like a charm. I'm using subpath because i'm launching instances on demand(programatically). Thanks again!!

@icaliman84
Copy link

This is a very old issue and the docs have been changed. These days we recommend caddy.
See https://github.com/cdr/code-server/blob/master/doc/guide.md

thanks for the quick reply, so i ended up doing it with the ingress alone, just had to add the annotations nginx.ingress.kubernetes.io/rewrite-target, nginx.ingress.kubernetes.io/app-root and setting the path to /{subpath}(/|$)(.*) and it just worked like a charm. I'm using subpath because i'm launching instances on demand(programatically). Thanks again!!
Do you mind sharing the working ingress config? I am trying to do the same.

@jsjoeio
Copy link
Contributor

jsjoeio commented Sep 8, 2021

cc @bpmct

@cheoalfredo
Copy link

@icaliman84 it's a regular ingress, for the path of the service i have "/somepath(/|$)(.*)" and these annotations : "nginx.ingress.kubernetes.io/rewrite-target: /$2" and "nginx.ingress.kubernetes.io/app-root: /somepath". this is all server side generated and this project is no longer running, that's why i did not provide a full ingress sample, if you have some time i can provision the environment and send you a full sample later!!

@thuzhf
Copy link

thuzhf commented Sep 14, 2023

@code-asher I cannot find the --base-path option in code-server 4.16.1.
image
image

Is this feature removed now? Why? This is a very useful feature.

@code-asher
Copy link
Member

code-asher commented Sep 15, 2023 via email

@thuzhf
Copy link

thuzhf commented Sep 17, 2023

It was removed because code-server uses relative paths now. In other words, it should work no matter where you host it, without having to manually specify the path. If you are having problems there could be a bug in code-server, or it could be a bug in your configuration. Feel free to open an issue with details!

@code-asher I see. Thanks for explaining!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants