k8s安装nginx部署
时间: 2023-09-26 18:07:01 浏览: 123
k8s上安装nginx
5星 · 资源好评率100%
对于Kubernetes中安装和部署Nginx,可以使用Deployment或Pod来实现。
使用Deployment:
首先,创建一个为deploy-nginx.yaml的文件,并在文件中添加以下内容:
```yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
namespace: dev
spec:
replicas: 3
selector:
matchLabels:
run: nginx
template:
metadata:
labels:
run: nginx
spec:
containers:
- image: nginx:1.17.1
name: nginx
ports:
- containerPort: 80
protocol: TCP
```
然后,使用kubectl命令来创建该Deployment:
```shell
kubectl apply -f deploy-nginx.yaml
```
使用Pod:
创建一个名为pod-nginx.yaml的文件,并在文件中添加以下内容:
```yaml
apiVersion: v1
kind: Pod
metadata:
name: nginx
namespace: dev
spec:
containers:
- image: nginx:1.17.1
name: pod
ports:
- name: nginx-port
containerPort: 80
protocol: TCP
```
然后,使用kubectl命令来创建该Pod:
```shell
kubectl apply -f pod-nginx.yaml
```
另外,还可以使用配置方式来安装和部署Nginx。创建一个名为nginx.yaml的文件,并在文件中添加以下内容:
```yaml
apiVersion: v1
kind: Pod
metadata:
name: nginx
namespace: dev
labels:
version: "3.0"
env: "test"
spec:
containers:
- image: nginx:1.17.1
name: pod
ports:
- name: nginx-port
containerPort: 80
protocol: TCP
```
然后,使用kubectl命令来创建该Pod:
```shell
kubectl apply -f nginx.yaml
```
这些方法可以根据需要选择其中之一来安装和部署Nginx。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* *3* [【k8s】4、组件](https://blog.csdn.net/hancoder/article/details/118053399)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 100%"]
[ .reference_list ]
阅读全文