k8s——部署一个nginx应用
创建nginx-deployment.yaml文件apiVersion: apps/v1kind: Deploymentmetadata:name: nginxdeployspec:replicas: 1selector:matchLabels:name: nginxdeploytemplate:metadata:la...
·
创建nginx-deployment.yaml文件
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginxdeploy
spec:
replicas: 1
selector:
matchLabels:
name: nginxdeploy
template:
metadata:
labels:
name: nginxdeploy
spec:
containers:
- name: nginxdeploy
image: nginx
ports:
- containerPort: 80
确保所有节点都有nginx镜像
使用kubectl生成pod
kubecet create -f nginx-deployment.yaml
查看
kubectl get pod
创建nginx-service.yaml
apiVersion: v1
kind: Service
metadata:
name: nginxdeploy
spec:
type: NodePort
ports:
- port: 82
protocol: TCP
targetPort: 80
name: http
nodePort: 30055
selector:
name: nginxdeploy
查看创建的service
kubectl get svc
通过cluster-ip与对应的端口号验证
curl 10.96.109.77:82
至此只能通过集群内部访问,外部是访问不了的,需要通过相关配置才能实现
更多推荐
已为社区贡献10条内容
所有评论(0)