Kubernetes 测试环境

标签 kubernetes virtualhost

我有一个托管的 VPS,我想使用这台机器作为单节点 Kubernetes 测试环境。是否可以在 VPS 上创建单节点 Kubernetes 集群,使用 GitLab 等将 pod 部署到其中,并从机器外部测试应用程序?我想在本地开发,推送到 git,然后部署在这个测试/登台环境上。

谢谢

最佳答案

回答整个问题的一部分:

I have a hosted VPS and I would like to use this machine as a single node kubernetes test environment.

一个好的起点可能是引用我自己的答案的部分 Serverfault :

There are a lot of options to choose from. Each solution will have it's advantages and disadvantages. It will also depend on the operating system your VM is deployed with.

Some of the options are the following:

Each of the solutions linked above have a link to it's respective homepage. You can find there installation steps/tips. Each solution is different and I encourage you to check if selected option suits your needs.

您需要检查上述每个解决方案的网络部分,因为其中一些解决方案将具有更容易/更困难的过程来将您的工作负载暴露在环境之外(使其可从 Internet 访问)。

这一切都归结为您的要求/期望是什么以及每个解决方案的要求是什么。


MicroK8S 设置:

我确实同意社区成员@Sekru 提供的答案,但我也认为为此类设置添加一个示例可能是有益的。假设您有一个 microk8s 兼容操作系统:

  • sudo snap install microk8s --classic
  • sudo microk8s 启用入口
  • sudo microk8s kubectl 创建部署 nginx --image=nginx
  • sudo microk8s kubectl 公开部署 nginx --port=80 --type=NodePort
  • sudo microk8s kubectl apply -f ingress.yaml 其中 ingress.yaml 是包含以下内容的文件:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: minimal-ingress
spec:
  ingressClassName: public # <-- IMPORTANT
  rules:
  - http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: nginx
            port:
              number: 80

完成上述步骤后,您应该能够通过以下方式从主机外部联系您的部署:

  • curl http://IP 地址

Side notes!

  • A setup like that will allow expose your workload on a NodePort (allocated port on each node from 30000 to 32767).
  • From the security perspective I would consider using your VPS provider firewalls to limit the traffic coming to your instance to allow only subnets that you are connecting from.

从 Gitlab 与 Kubernetes 集成的角度来看,我认为您可以通过关注它的页面找到有用的信息:

有关 Kubernetes 的其他资源:

关于Kubernetes 测试环境,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65762452/

相关文章:

nginx - 使用 ConfigMap 添加 header 到 NGINX Ingress 不起作用

apache - 网站在 IE 6 以外的浏览器中显示完美

kubernetes - Kubernetes服务显示外部IP '<pending>'。如何启用它?

go - 如何使用 go 客户端在 kubernetes 服务上观看事件

kubernetes - Openshift-重命名路线

apache - localhost 子域上的 ssl 证书不起作用

linux - 在 Apache 2.4 中添加基于 IP 的虚拟主机

apache - 如何在同一IP的不同域名上应用不同的SSL证书?

ubuntu - apache2:在本地服务器的同一域下托管多个站点

rest - 使用 REST API 访问 Kubernetes API