k8s——部署一个nginx应用

创建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

在这里插入图片描述
至此只能通过集群内部访问,外部是访问不了的,需要通过相关配置才能实现

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章