对 kubernetes/kops 来说非常新,我已经按照 aws 上的 kops 教程进行操作,并且创建了一个集群。我想在集群上从 hub.docker 运行一个非常简单的容器,我该如何将这个容器添加到集群中?它是在集群配置文件中还是我需要向节点添加另一个图像。
2 回答
In Kubernetes, container could be run as Pod, which is a resource in Kubernetes.
You could prepare a yaml or json file to create your pod with command kubectl create -f $yourfile
Example could be found here https://github.com/kubernetes/kubernetes/blob/master/examples/javaweb-tomcat-sidecar/javaweb.yaml
And for images by default, Kubernetes will pull images from Docker Hub, if not existing in your cluster, and also depends on your ImagePullPolicy
You just need to specify your image at section spec.containers.image
Hope this will help you.
例如,要在集群中运行 nginx Web 服务器,您可以使用下面的命令行,这将从 docker hub 下载图像并启动实例。
kubectl 运行 nginx --image=nginx --port=80
这是命令https://kubernetes.io/docs/user-guide/kubectl/v1.8/。
要运行您的图像,请使用您的图像名称更改 nginx。
- 其他选项是创建部署 yaml 文件并运行容器。
apiVersion: extensions/v1beta1 kind: Deployment metadata: labels: run: nginx name: nginx spec: replicas: 2 selector: matchLabels: run: nginx strategy: rollingUpdate: maxSurge: 1 maxUnavailable: 1 type: RollingUpdate template: metadata: labels: run: nginx tier: frontend spec: containers: - image: nginx:1.10 imagePullPolicy: IfNotPresent name: nginx lifecycle: preStop: exec: command: ["/usr/sbin/nginx","-s","quit"] restartPolicy: Always terminationGracePeriodSeconds: 30
将上述文件存储在文件中,nginx.yaml
然后使用 kubectl 命令运行它。
kubectl create -f nginx.yaml