# 参考:
# https://cloud.tencent.com/developer/ask/sof/1518474
# https://stackoverflow.com/questions/64758012/location-of-kubernetes-config-directory-with-docker-desktop-on-windows
# 当 Kubernetes 使用 NodePort 方式对外提供服务的时候, Kubernetes 默认使用 30000-32767 端口
# 如果需要使用 80, 443, 3306 等端口,会给出如下错误提示:
# provided port is not in the valid range. The range of valid ports is 30000-32767
# 如果需要使用 30000 以下端口 需要执行如下操作:
# 运行一个特权docker容器
docker run -it --privileged --pid=host debian nsenter -t 1 -m -u -n -i sh
# 编辑 kube-apiserver 配置文件
vi /etc/kubernetes/manifests/kube-apiserver.yaml
# 搜索 kube-apiserver
# 在该命令的参数列表最后增加以下内容:
# - --service-node-port-range=1-65535
# 保存修改
exit
# 退出该特权容器后, kubeapi-server 将会使用新的命令参数自动重启
# 登录 Kubernetes Dashboard 检查配置是否生效
# kubectl apply -f nginx.yaml
---
apiVersion: v1
kind: Namespace
metadata:
name: arno
labels:
name: arno
---
apiVersion: apps/v1
kind: Deployment
metadata:
namespace: arno
name: nginx
spec:
selector:
matchLabels:
app: nginx
replicas: 1
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.23.1
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
namespace: arno
name: nginx
spec:
type: NodePort
selector:
app: nginx
ports:
- protocol: TCP
port: 80
targetPort: 80
nodePort: 80
kubectl apply -f nginx.yaml
curl -L localhost