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

在這裏插入圖片描述
至此只能通過集羣內部訪問,外部是訪問不了的,需要通過相關配置才能實現

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