不同版本k8s的yaml写法不太一样,我的是1.22.0版本
1、创建nginx-svc.yaml文件
apiVersion: v1 kind: Service metadata: namespace: default name: nginx-svc labels: name: nginx-svc spec: type: NodePort ports: - port: 80 protocol: TCP targetPort: 80 name: http nodePort: 30001 selector: name: nginx-pod
2、创建nginx的service服务
kubectl create -f nginx-svc.yaml
3、查看nginx的service实例
kubectl get svc -n default -owide
或
kubectl get service
4、创建nginx 副本控制器
4.1创建nginx-rc.yaml文件
apiVersion: v1 kind: ReplicationController metadata: namespace: default name: nginx-rc labels: name: nginx-rc spec: replicas: 1 selector: name: nginx-pod template: metadata: labels: name: nginx-pod spec: containers: - name: nginx image: nginx imagePullPolicy: IfNotPresent ports: - containerPort: 80
4.2创建nginx的ReplicationController
kubectl create -f nginx-rc.yaml
4.3查看nginx的pod
kubectl get pod -n default -owide
kubectl get pods
5、通过这里可以看到部署到节点1上了
直接在浏览器里输入节点1的ip+30001,输出
主要参考:https://blog.csdn.net/Happy123568/article/details/109551695?utm_medium=distribute.pc_relevant.none-task-blog-2~default~baidujs_baidulandingword~default-5.control&spm=1001.2101.3001.4242