Kubernetes 测试环境

Kubernetes test environment

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

谢谢

是的,使用 microk8s。对于从外部访问,使用入口插件

回答整个问题的部分:

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.

您需要查看上述每个解决方案的网络部分,因为其中一些解决方案 easier/more 将您的工作负载公开到环境之外(使其可从 Internet 访问)会遇到困难。

这一切都归结为您的 requirements/expectations 以及每个解决方案的要求。


MicroK8S 设置:

我同意社区成员@Sekru 提供的答案,但我也认为为此类设置添加示例可能会有所帮助。假设你有一个 microk8s 兼容 OS:

  • sudo snap install microk8s --classic
  • sudo microk8s enable ingress
  • sudo microk8s kubectl create deployment nginx --image=nginx
  • sudo microk8s kubectl expose deployment 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

完成上述步骤后,您应该可以通过以下方式从主机之外的地方联系您的 Deployment

  • curl http://IP-ADDRESS

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 的其他资源: