官术网_书友最值得收藏!

Pod example

Let's take a quick look at a pod in action. We will spin up a Node.js application on the cluster. You'll need a GCE cluster running for this; if you don't already have one started, refer to the Our first cluster section in Chapter 1, Introduction to Kubernetes.

Now, let's make a directory for our definitions. In this example, I will create a folder in the /book-examples subfolder under our home directory:

$ mkdir book-examples
$ cd book-examples
$ mkdir 02_example
$ cd 02_example
Downloading the example code
You can download the example code files from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

Use your favorite editor to create the following file:

apiVersion: v1 
kind: Pod
metadata:
name: node-js-pod
spec:
containers:
- name: node-js-pod
image: bitnami/apache:latest
ports:
- containerPort: 80

Listing 2-1: nodejs-pod.yaml

This file creates a pod named node-js-pod with the latest bitnami/apache container running on port 80. We can check this using the following command:

$ kubectl create -f nodejs-pod.yaml

The output is as follows:

pod "node-js-pod" created

This gives us a pod running the specified container. We can see more information on the pod by running the following command:

$ kubectl describe pods/node-js-pod

You'll see a good deal of information, such as the pod's status, IP address, and even relevant log events. You'll note the pod IP address is a private IP address, so we cannot access it directly from our local machine. Not to worry, as the kubectl exec command mirrors Docker's exec functionality. Once the pod shows to be in a running state, we can use this feature to run a command inside a pod:

$ kubectl exec node-js-pod -- curl <private ip address>
By default, this runs a command in the first container it finds, but you can select a specific one using the -c argument.

After running the command, you should see some HTML code. We'll have a prettier view later in the chapter, but for now, we can see that our pod is indeed running as expected.

主站蜘蛛池模板: 凤冈县| 巩留县| 宿松县| 荃湾区| 黑山县| 塘沽区| 郁南县| 县级市| 沅陵县| 工布江达县| 九寨沟县| 彭山县| 杭锦后旗| 永仁县| 临猗县| 屏东市| 汉寿县| 芮城县| 吉安县| 盐津县| 大同县| 台湾省| 桦川县| 安岳县| 临城县| 临桂县| 纳雍县| 历史| 洛宁县| 盐津县| 措美县| 都兰县| 中西区| 隆德县| 正安县| 扶风县| 樟树市| 禹城市| 茌平县| 卓资县| 肥东县|