Kubernetes : Create Pods
2015/12/13
|
Containers in Kubernetes Cluster are managed as a Pod.
It's possible to run Containers to create Pods.
This example is based on the environment like follows.
+---------------------+
| [ Admin Node ] |
| dlp.server.world |
| |
+----------+----------+
|
+----------------------+ | +----------------------+
| [ Node01 ] |10.0.0.51 | 10.0.0.52| [ Node02 ] |
| node01.server.world +----------+----------+ node02.server.world |
| | | |
+----------------------+ +----------------------+
|
For example, Create a Pod with single container which httpd is installed.
| |
| [1] |
Create a Container image which httpd is installed on a Node, refer to here.
The image name is "web_server" for configuratuion on this exmaple. |
| [2] | Copy a container image just created above to all other Nodes like follows. |
# output container image to a file
[root@node01 ~]#
docker save web_server > web_server.tar
# copy the image to other Nodes
[root@node01 ~]#
scp web_server.tar node02:/root/web_server.tar
|
| [3] | Load the comtainer image just copied. |
| [root@node02 ~]#
docker load < web_server.tar
[root@node02 ~]#
docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE web_server latest 084ef53f3d83 11 minutes ago 283.9 MB docker.io/centos latest ce20c473cd8a 8 weeks ago 172.3 MB |
| [4] | Create a Pod on Admin Node. |
[root@dlp ~]#
vi pod-webserver.yaml
apiVersion: v1 kind: Pod metadata: # name of Pod name: httpd labels: # rabel of Pod app: web_server spec: containers: # name of Container - name: httpd # Container image image: web_server ports: # Container Port - containerPort: 80
# create Pod
[root@dlp ~]#
kubectl create -f pod-webserver.yaml
pods/httpd
# show Pods list
[root@dlp ~]#
kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE NODE httpd 0/1 Running 0 8s node01
# display assigned IP address on the Pod
[root@dlp ~]#
kubectl get pod httpd -o yaml | grep "podIP"
podIP: 172.16.35.10
# access to the Pod
[root@dlp ~]#
curl http://172.16.35.10/
Hello DockerFile |
| [5] | If you'd like to remove a Pod, do like follows. |
| [root@dlp ~]#
kubectl delete pod httpd
pods/httpd |
Nenhum comentário:
Postar um comentário