k8s部署nginx
创建namespace
nginx-namespace.yaml
apiVersion: v1
kind: Namespace
metadata:
name: ns-nginx
创建Deployment
nginx-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
namespace: ns-nginx
spec:
selector:
matchLabels:
app: nginx-app
replicas: 2
template:
metadata:
labels:
app: nginx-app
spec:
containers:
- name: nginx
image: swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/nginx:stable
ports:
- containerPort: 80
创建Service
nginx-service.yaml
apiVersion: v1
kind: Service
metadata:
name: nginx-service
namespace: ns-nginx
labels:
app: nginx-app
spec:
selector:
app: nginx-app
ports:
- protocol: TCP
port: 80
targetPort: 80
nodePort: 32080
type: NodePort
启动
kubectl apply -f nginx-namespace.yaml
kubectl apply -f .
查看
kubectl get pod -n ns-nginx
kubectl get svc -n ns-nginx
访问
http://10.0.2.12:32080/
10.0.2.12
为宿主机ip,32080
为tomcat Service的port。