一看必会系列:kubernetes使用yaml部署nginx集群
注意空行和格式
1 创建nginx-rc.yaml
vim "nginx-rc.yaml" 18L, 350C
apiVersion: v1
kind: ReplicationController
metadata:
name: nginx-controller
spec:
replicas: 2
selector:
name: nginx-selector
template:
metadata:
labels:
name: nginx-selector
spec:
containers:
– name: nginx
image: 192.168.142.131:5000/nginx:v1
ports:
– containerPort: 80
2 创建nginx-service-nodeport.yaml
vim nginx-service-nodeport.yaml
apiVersion: v1
kind: Service
metadata:
name: nginx-service-nodeport
spec:
ports:
– port: 8800
targetPort: 80
protocol: TCP
type: NodePort
selector:
name: nginx-selector
~
3 创建pod
kubectl create -f nginx-rc.yaml
4 创建service
kubectl create -f nginx-service-nodeport.yaml
看RC状态
[root@centos011 ~]# kubectl get rc
NAME DESIRED CURRENT READY AGE
nginx-controller 2 2 2 26m 2个是正常
看service 状态
[root@centos011 ~]# kubectl get service
NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
my-nginx-974504764-z1zwq 192.168.142.107 <pending> 80:32594/TCP 17h
my-nginx-974504764-z3mtw 192.168.142.252 <pending> 80:30025/TCP 17h
nginx-service-nodeport 192.168.142.53 <nodes> 8800:30572/TCP 26m service 状态 8800映射到30672
看nodeport可对外提供服务的端口
[root@centos011 ~]# kubectl describe service nginx-service-nodeport
Name: nginx-service-nodeport
Namespace: default
Labels: <none>
Selector: name=nginx-selector
Type: NodePort
IP: 192.168.142.53
Port: <unset> 8800/TCP 提供service端口
NodePort: <unset> 30572/TCP 外部能访问的端口
Endpoints: 172.17.100.2:80,172.17.73.2:80 容器内部端口
Session Affinity: None
No events.
[root@centos011 ~]#
更详细的
[root@centos011 ~]# kubectl get pods –all-namespaces -o wide
NAMESPACE NAME READY STATUS RESTARTS AGE IP NODE
default nginx-controller-mcm0s 1/1 Running 0 28m 172.17.100.2 192.168.142.132
default nginx-controller-vq0dl 1/1 Running 0 28m 172.17.73.2 192.168.142.130
kube-system kubernetes-dashboard-3820983789-jnsdz 1/1 Running 0 18h 172.17.88.3 192.168.142.131
[root@centos011 ~]#
访问方式
因为service使用的是NodePort方式,所以在任何一个节点访问31152这个端口都可以访问nginx
https://www.cnblogs.com/puroc/p/5764330.html
暂时还木有人评论,坐等沙发!