k8s 通过命令行创建容器
一、编辑部署脚本centos7.json[root@localhost ~]# vim centos7.json[root@localhost ~]# cat centos7.json{"kind": "Deployment","apiVersion": "extensions/v1beta1","metadata": {"name": "vhost-centos7ssh","namespace"
·
一、编辑部署脚本centos7.json
[root@localhost ~]# vim centos7.json
[root@localhost ~]# cat centos7.json
{
"kind": "Deployment",
"apiVersion": "extensions/v1beta1",
"metadata": {
"name": "vhost-centos7ssh",
"namespace": "default",
"selfLink": "/apis/extensions/v1beta1/namespaces/default/deployments/vhost-centos7ssh",
"uid": "b1a3aa35-f432-11ea-ba87-000c29432e9e",
"resourceVersion": "51304",
"generation": 1,
"creationTimestamp": "2020-09-11T13:28:35Z",
"labels": {
"app": "vhost-centos7ssh"
},
"annotations": {
"deployment.kubernetes.io/revision": "1"
}
},
"spec": {
"replicas": 1,
"selector": {
"matchLabels": {
"app": "vhost-centos7ssh"
}
},
"template": {
"metadata": {
"name": "vhost-centos7ssh",
"creationTimestamp": null,
"labels": {
"app": "vhost-centos7ssh"
}
},
"spec": {
"containers": [
{
"name": "vhost-centos7ssh",
"image": "centos7-ssh:v2",
"resources": {},
"terminationMessagePath": "/dev/termination-log",
"imagePullPolicy": "IfNotPresent",
"securityContext": {
"privileged": false
}
}
],
"restartPolicy": "Always",
"terminationGracePeriodSeconds": 30,
"dnsPolicy": "ClusterFirst",
"securityContext": {}
}
},
"strategy": {
"type": "RollingUpdate",
"rollingUpdate": {
"maxUnavailable": 1,
"maxSurge": 1
}
}
},
"status": {
"observedGeneration": 1,
"replicas": 1,
"updatedReplicas": 1,
"availableReplicas": 1,
"conditions": [
{
"type": "Available",
"status": "True",
"lastUpdateTime": "2020-09-11T13:28:35Z",
"lastTransitionTime": "2020-09-11T13:28:35Z",
"reason": "MinimumReplicasAvailable",
"message": "Deployment has minimum availability."
}
]
}
}
[root@localhost ~]#
注:
"name": "vhost-centos7ssh", 任务名称
"namespace": "default", 命名空间 名称
"image": "centos7-ssh:v2", 镜像名称
"imagePullPolicy": "IfNotPresent", 拉镜像顺序,本地仓库镜像,然后是外部仓库
"replicas": 1, 仓库容器数,1台
二、执行创建语句
[root@localhost ~]# kubectl create -f centos7.json
deployment "vhost-centos7ssh" created
三、创建外部服务,使局域网其他机器可直接SSH远程
[root@localhost ~]# kubectl expose deployment vhost-centos7ssh --port=22 --target-port=22 --type=LoadBalancer
service "vhost-centos7ssh" exposed
deployment vhost-centos7ssh 部署名称
四、SSH连接测试
1、找出外部端口
2、SSH连接
[root@localhost ~]# ssh -p 30571 192.168.1.110
The authenticity of host '[192.168.1.110]:30571 ([192.168.1.110]:30571)' can't be established.
ECDSA key fingerprint is SHA256:15y8WG7DlrTDPabFd7FZogZrUb5orDers7E2i3TIRk8.
ECDSA key fingerprint is MD5:be:79:8e:a1:21:9f:e1:b2:7e:de:67:2a:8f:d6:a4:10.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '[192.168.1.110]:30571' (ECDSA) to the list of known hosts.
root@192.168.1.110's password:
Last login: Sat Sep 12 13:18:51 2020 from 172.17.14.0
[root@vhost-centos7ssh-2692673234-cvs03 ~]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1472
inet 172.17.3.3 netmask 255.255.255.0 broadcast 0.0.0.0
inet6 fe80::42:acff:fe11:303 prefixlen 64 scopeid 0x20<link>
ether 02:42:ac:11:03:03 txqueuelen 0 (Ethernet)
RX packets 169 bytes 20333 (19.8 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 128 bytes 20334 (19.8 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
--------------------------end
更多推荐
已为社区贡献7条内容
所有评论(0)