使用k3s集群部署Nginx的pod

使用k3s搭建Nginx的Pod方法。

由于最近有机会搭建Nginx的反向代理服务器,因此在这里记录下相关步骤。

安装k3s

首先,安装用于部署Pod的k3s作为基础。执行以下k3s提供的安装脚本:

$ curl -sfL https://get.k3s.io | sh -

如果安装正常,下面的kubectl命令应该可以运行。

$ sudo kubectl get nodes
NAME          STATUS   ROLES                  AGE     VERSION

船舶的舵准备

进行Helm的安装。由于Helm的安装脚本也存在,因此执行该脚本。

$ curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash

然后添加helm的存储库。这次存储库的名称为my-repo。

$ helm repo add my-repo https://charts.bitnami.com/bitnami

安装Nginx的Pod。

执行以下操作,使用Helm来安装Nginx。

$ helm install my-release my-repo/nginx

搭建一个Pod

最后要启动pod。

$ helm upgrade my-release my-repo/nginx -f nginx-values.yaml

如果收到以下的回复,表示能够正常运行。

Release "my-release" has been upgraded. Happy Helming!
NAME: my-release
LAST DEPLOYED: Mon Jan 16 10:46:57 2023
NAMESPACE: default
STATUS: deployed
REVISION: 2
TEST SUITE: None
NOTES:
CHART NAME: nginx
CHART VERSION: 13.2.21
APP VERSION: 1.23.3

** Please be patient while the chart is being deployed **
NGINX can be accessed through the following DNS name from within your cluster:

    my-release-nginx.default.svc.cluster.local (port 80)

To access NGINX from outside the cluster, follow the steps below:

1. Get the NGINX URL by running these commands:

  NOTE: It may take a few minutes for the LoadBalancer IP to be available.
        Watch the status with: 'kubectl get svc --namespace default -w my-release-nginx'

    export SERVICE_PORT=$(kubectl get --namespace default -o jsonpath="{.spec.ports[0].port}" services my-release-nginx)
    export SERVICE_IP=$(kubectl get svc --namespace default my-release-nginx -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
    echo "http://${SERVICE_IP}:${SERVICE_PORT}"

以下是一个对话范例:

Person A: 请参照这个指南来完成任务。
Person B: 好的,我会按照这个指南来做。
(Translation)
A: Please refer to this guide to complete the task.
B: Okay, I will follow this guide to do it.

K3s 安装步骤 | hassiweb 的备忘录 – GitLab

Bitnami将NGINX开源软件打包并发布于GitHub。