1、 创建命令空间
kubectl create namespace test
2、编辑 nginx-deployment.yaml
--- apiVersion: apps/v1 kind: Deployment metadata: name: nginx namespace: test labels: app: nginx spec: replicas: 2 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx:latest imagePullPolicy: IfNotPresent ports: - name: http protocol: TCP containerPort: 80 resources: limits: cpu: "1.0" memory: 512Mi requests: cpu: "0.5" memory: 128Mi --- apiVersion: v1 kind: Service metadata: annotations: name: nginx-test-service namespace: test spec: ports: - port: 80 targetPort: 80 nodePort: 32001 protocol: TCP selector: app: nginx sessionAffinity: None type: NodePort
3、发布nginx应用
kubectl create -f nginx-deployment.yaml
4、查看发布的pods
kubectl get pods -n test
详细查看,注意部署的node节点
kubectl get pods -n test -o wide
查看服务和pods
kubectl get pods,svc -n test -o wide
注意服务端口为32001
5、访问nginx服务,node1节点的ip是192.168.143.134,服务端口32001
至此,简单发布完成
参考链接:
https://www.cnblogs.com/voipman/p/15378589.html
标签:kubectl,name,部署,app,nginx,test,k8s,pods From: https://www.cnblogs.com/fireblackman/p/16636467.html