一、发布Django项目
1.1 创建namespace
[root@vm-k8s-master ~]# kubectl create namespace cloudops
namespace/cloudops created
[root@vm-k8s-master ~]# kubectl get po -n cloudops
No resources found in cloudops namespace.
[root@vm-k8s-master ~]#
1.2 创建pod
[root@vm-k8s-master ~]# kubectl -n cloudops run opsserver --image=10.60.128.219:888/cloudops/cloudops_test:78b8ccc --port=9001 --restart=Never
pod/opsserver created
[root@vm-k8s-master ~]# kubectl get po -n cloudops
NAME READY STATUS RESTARTS AGE
opsserver 1/1 Running 0 18s
[root@vm-k8s-master ~]#
1.3 映射端口到k8s集群
[root@vm-k8s-master ~]# kubectl -n cloudops expose pod opsserver --target-port=9001 --port=9001
service/opsserver exposed
[root@vm-k8s-master ~]# kubectl get svc -n cloudops
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
opsserver ClusterIP 10.0.0.138 <none> 9001/TCP 17s
[root@vm-k8s-master ~]#
说明:
- --target-port: 容器内部服务的端口
- --port: 对外暴露可访问的端口
- --type: service类型 可以指定,默认是ClusterIP