参考文档
https://blog.51cto.com/zhangxueliang/2968407
指令帮助
student@master01:~$ kubectl run -h
Create and run a particular image in a pod.
Examples:
# Start a nginx pod
kubectl run nginx --image=nginx
# Start a hazelcast pod and let the container expose port 5701
kubectl run hazelcast --image=hazelcast/hazelcast --port=5701
指令作用
创建并运行一个特定镜像的Pod
历史版本默认创建的是一个Deployment,新版本中创建的Pod
常用参数
—image=nginx 指定镜像
—replicas=5 指定副本数量
—dry-run 打印对象不创建
—restart Pod的重启策略
—env=”POD_NAMESPACE=default” 设置环境变量
—port=5701 暴露端口
—expose如果为true,会创建有ClusterIP的service此时需要搭配参数—port,默认为false;
—labels=”app=nginx,env=prod” 指定Pod的标签
—image-pull-policy 指定镜像的拉取策略
历史版本—generator参数已经废弃,新版本已经无此参数
指令议题
https://github.com/kubernetes/kubernetes/pull/87077
指令样例
对象打印
student@master01:~$ kubectl run podname --image=nginx --dry-run=client -o yaml
apiVersion: v1
kind: Pod
metadata:
creationTimestamp: null
labels:
run: podname
name: podname
spec:
containers:
- image: nginx
name: podname
resources: {}
dnsPolicy: ClusterFirst
restartPolicy: Always
status: {}
student@master01:~$
进入终端
student@master01:~$ kubectl run podname2 -it --image=nginx -- /bin/bash
root@podname2:/# exit
exit
Session ended, resume using 'kubectl attach podname2 -c podname2 -i -t' command when the pod is running