一、部署系统环境服务

  一)部署Nginx

  1、创建管理目录及其相关yaml文件

mkdir -p /opt/kubernetes/yaml/nginx

K8s实战篇_系统环境K8s实战篇_K8s_02

apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 2
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.0
ports:
- containerPort: 80

nginx-deployment.yaml

K8s实战篇_系统环境K8s实战篇_K8s_02

kind: Service
apiVersion: v1
metadata:
name: nginx-service
spec:
selector:
app: nginx
ports:
- protocol: TCP
port: 80
targetPort: 80

nginx-service.yaml

  2、创建nginx

cd /opt/kubernetes/yaml/
kubectl create -f nginx/

  3、验证nginx服务