Fix code highlight
parent
6c1cb971c2
commit
b5c3205f64
|
@ -35,7 +35,7 @@ spec:
|
||||||
|
|
||||||
我们可以在 Pod 中为容器使用 command 为容器指定启动参数:
|
我们可以在 Pod 中为容器使用 command 为容器指定启动参数:
|
||||||
|
|
||||||
```Bash
|
```bash
|
||||||
command: ["/bin/bash","-c","bootstrap.sh"]
|
command: ["/bin/bash","-c","bootstrap.sh"]
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -59,7 +59,7 @@ spec:
|
||||||
restartPolicy: OnFailure
|
restartPolicy: OnFailure
|
||||||
```
|
```
|
||||||
|
|
||||||
```Bash
|
```bash
|
||||||
$ kubectl create -f cronjob.yaml
|
$ kubectl create -f cronjob.yaml
|
||||||
cronjob "hello" created
|
cronjob "hello" created
|
||||||
```
|
```
|
||||||
|
|
|
@ -121,7 +121,7 @@ kubectl 也支持级联删除。 通过设置 `--cascade` 为 true,可以使
|
||||||
|
|
||||||
下面是一个例子,使一个 ReplicaSet 的 Dependent 对象成为孤儿 Dependent:
|
下面是一个例子,使一个 ReplicaSet 的 Dependent 对象成为孤儿 Dependent:
|
||||||
|
|
||||||
```Bash
|
```bash
|
||||||
kubectl delete replicaset my-repset --cascade=false
|
kubectl delete replicaset my-repset --cascade=false
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -240,7 +240,7 @@ Ingress controller启动时附带一些适用于所有Ingress的负载平衡策
|
||||||
|
|
||||||
假如你想要向已有的ingress中增加一个新的Host,你可以编辑和更新该ingress:
|
假如你想要向已有的ingress中增加一个新的Host,你可以编辑和更新该ingress:
|
||||||
|
|
||||||
```Bash
|
```bash
|
||||||
$ kubectl get ing
|
$ kubectl get ing
|
||||||
NAME RULE BACKEND ADDRESS
|
NAME RULE BACKEND ADDRESS
|
||||||
test - 178.91.123.132
|
test - 178.91.123.132
|
||||||
|
|
|
@ -186,7 +186,7 @@ $ kubectl logs myapp-pod -c init-mydb # Inspect the second init container
|
||||||
|
|
||||||
一旦我们启动了 `mydb` 和 `myservice` 这两个 Service,我们能够看到 Init 容器完成,并且 `myapp-pod` 被创建:
|
一旦我们启动了 `mydb` 和 `myservice` 这两个 Service,我们能够看到 Init 容器完成,并且 `myapp-pod` 被创建:
|
||||||
|
|
||||||
```Bash
|
```bash
|
||||||
$ kubectl create -f services.yaml
|
$ kubectl create -f services.yaml
|
||||||
service "myservice" created
|
service "myservice" created
|
||||||
service "mydb" created
|
service "mydb" created
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
|
|
||||||
代码如下:
|
代码如下:
|
||||||
|
|
||||||
```Go
|
```go
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -154,7 +154,7 @@ New image -> harbor-001.jimmysong.io/library/analytics-docker-test:Build_9
|
||||||
|
|
||||||
查看Deployment的event。
|
查看Deployment的event。
|
||||||
|
|
||||||
```Bash
|
```bash
|
||||||
$ kubectl describe deployment filebeat-test
|
$ kubectl describe deployment filebeat-test
|
||||||
Name: filebeat-test
|
Name: filebeat-test
|
||||||
Namespace: default
|
Namespace: default
|
||||||
|
|
|
@ -266,7 +266,7 @@ users:
|
||||||
|
|
||||||
#### 示例文件相关操作命令
|
#### 示例文件相关操作命令
|
||||||
|
|
||||||
```Bash
|
```bash
|
||||||
$ kubectl config set preferences.colors true
|
$ kubectl config set preferences.colors true
|
||||||
$ kubectl config set-cluster cow-cluster --server=http://cow.org:8080 --api-version=v1
|
$ kubectl config set-cluster cow-cluster --server=http://cow.org:8080 --api-version=v1
|
||||||
$ kubectl config set-cluster horse-cluster --server=https://horse.org:4443 --certificate-authority=path/to/my/cafile
|
$ kubectl config set-cluster horse-cluster --server=https://horse.org:4443 --certificate-authority=path/to/my/cafile
|
||||||
|
|
|
@ -271,7 +271,7 @@ namespace: 7 bytes
|
||||||
|
|
||||||
然后,确认已创建。如:
|
然后,确认已创建。如:
|
||||||
|
|
||||||
```Bash
|
```bash
|
||||||
$ kubectl get secrets myregistrykey
|
$ kubectl get secrets myregistrykey
|
||||||
NAME TYPE DATA AGE
|
NAME TYPE DATA AGE
|
||||||
myregistrykey kubernetes.io/.dockerconfigjson 1 1d
|
myregistrykey kubernetes.io/.dockerconfigjson 1 1d
|
||||||
|
|
|
@ -257,7 +257,7 @@ WARNING: No swap limit support
|
||||||
|
|
||||||
使用 kubectl 命令:
|
使用 kubectl 命令:
|
||||||
|
|
||||||
```Bash
|
```bash
|
||||||
$ kubectl cluster-info
|
$ kubectl cluster-info
|
||||||
Kubernetes master is running at https://108.59.85.141
|
Kubernetes master is running at https://108.59.85.141
|
||||||
KubeDNS is running at https://108.59.85.141/api/v1/namespaces/kube-system/services/kube-dns/proxy
|
KubeDNS is running at https://108.59.85.141/api/v1/namespaces/kube-system/services/kube-dns/proxy
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
|
|
||||||
通过运行以下命令生成私钥和证书签名请求(或CSR):
|
通过运行以下命令生成私钥和证书签名请求(或CSR):
|
||||||
|
|
||||||
```Bash
|
```bash
|
||||||
$ cat <<EOF | cfssl genkey - | cfssljson -bare server
|
$ cat <<EOF | cfssl genkey - | cfssljson -bare server
|
||||||
{
|
{
|
||||||
"hosts": [
|
"hosts": [
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
|
|
||||||
3. 显示 ReplicaSet 的信息:
|
3. 显示 ReplicaSet 的信息:
|
||||||
|
|
||||||
```
|
```bash
|
||||||
kubectl get replicasets
|
kubectl get replicasets
|
||||||
kubectl describe replicasets
|
kubectl describe replicasets
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@
|
||||||
|
|
||||||
4. 创建一个暴露该 Deployment 的 Service 对象:
|
4. 创建一个暴露该 Deployment 的 Service 对象:
|
||||||
|
|
||||||
```Bash
|
```bash
|
||||||
kubectl expose deployment hello-world --type=NodePort --name=example-service
|
kubectl expose deployment hello-world --type=NodePort --name=example-service
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -101,13 +101,13 @@
|
||||||
|
|
||||||
要删除 Service,输入以下命令:
|
要删除 Service,输入以下命令:
|
||||||
|
|
||||||
```
|
```bash
|
||||||
kubectl delete services example-service
|
kubectl delete services example-service
|
||||||
```
|
```
|
||||||
|
|
||||||
删除 Deployment、ReplicaSet 和正运行在 Pod 中的 Hello World 应用程序,输入以下命令:
|
删除 Deployment、ReplicaSet 和正运行在 Pod 中的 Hello World 应用程序,输入以下命令:
|
||||||
|
|
||||||
```
|
```bash
|
||||||
kubectl delete deployment hello-world
|
kubectl delete deployment hello-world
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -216,7 +216,7 @@ kubectl label nodes 172.20.0.115 edgenode=true
|
||||||
|
|
||||||
查看DaemonSet的启动情况:
|
查看DaemonSet的启动情况:
|
||||||
|
|
||||||
```Bash
|
```bash
|
||||||
$ kubectl -n kube-system get ds
|
$ kubectl -n kube-system get ds
|
||||||
NAME DESIRED CURRENT READY UP-TO-DATE AVAILABLE NODE-SELECTOR AGE
|
NAME DESIRED CURRENT READY UP-TO-DATE AVAILABLE NODE-SELECTOR AGE
|
||||||
traefik-ingress-lb 3 3 3 3 3 edgenode=true 2h
|
traefik-ingress-lb 3 3 3 3 3 edgenode=true 2h
|
||||||
|
|
|
@ -38,7 +38,7 @@ kubedns-svc.yaml
|
||||||
|
|
||||||
预定义的 RoleBinding `system:kube-dns` 将 kube-system 命名空间的 `kube-dns` ServiceAccount 与 `system:kube-dns` Role 绑定, 该 Role 具有访问 kube-apiserver DNS 相关 API 的权限;
|
预定义的 RoleBinding `system:kube-dns` 将 kube-system 命名空间的 `kube-dns` ServiceAccount 与 `system:kube-dns` Role 绑定, 该 Role 具有访问 kube-apiserver DNS 相关 API 的权限;
|
||||||
|
|
||||||
```Bash
|
```bash
|
||||||
$ kubectl get clusterrolebindings system:kube-dns -o yaml
|
$ kubectl get clusterrolebindings system:kube-dns -o yaml
|
||||||
apiVersion: rbac.authorization.k8s.io/v1beta1
|
apiVersion: rbac.authorization.k8s.io/v1beta1
|
||||||
kind: ClusterRoleBinding
|
kind: ClusterRoleBinding
|
||||||
|
|
|
@ -198,7 +198,7 @@ Kubernetes中应用的监控架构如图:
|
||||||
|
|
||||||
使用[scope.yaml](https://github.com/rootsongjc/kubernetes-handbook/blob/master/manifests/weave/scope.yaml)文件安装scope,该服务安装在`kube-system` namespace下。
|
使用[scope.yaml](https://github.com/rootsongjc/kubernetes-handbook/blob/master/manifests/weave/scope.yaml)文件安装scope,该服务安装在`kube-system` namespace下。
|
||||||
|
|
||||||
```Bash
|
```bash
|
||||||
$ kubectl apply -f scope.yaml
|
$ kubectl apply -f scope.yaml
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ Ingress Host:traefik.sample-webapp.io
|
||||||
|
|
||||||
通过向`sample-webapp`发送curl请求获取响应时间,直接curl后的结果为:
|
通过向`sample-webapp`发送curl请求获取响应时间,直接curl后的结果为:
|
||||||
|
|
||||||
```Bash
|
```bash
|
||||||
$ curl "http://10.254.149.31:8000/"
|
$ curl "http://10.254.149.31:8000/"
|
||||||
Welcome to the "Distributed Load Testing Using Kubernetes" sample web app
|
Welcome to the "Distributed Load Testing Using Kubernetes" sample web app
|
||||||
```
|
```
|
||||||
|
|
|
@ -93,7 +93,7 @@ enabled=1
|
||||||
|
|
||||||
验证源已经被激活。
|
验证源已经被激活。
|
||||||
|
|
||||||
```Bash
|
```bash
|
||||||
# yum repolist
|
# yum repolist
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -357,7 +357,7 @@ State: Peer in Cluster (Connected)
|
||||||
|
|
||||||
就像OpenShift中的其他组件一样,StorageClass也简单的用YAML文件定义:
|
就像OpenShift中的其他组件一样,StorageClass也简单的用YAML文件定义:
|
||||||
|
|
||||||
```Bash
|
```bash
|
||||||
# cat crs-storageclass.yaml
|
# cat crs-storageclass.yaml
|
||||||
kind: StorageClass
|
kind: StorageClass
|
||||||
apiVersion: storage.k8s.io/v1beta1
|
apiVersion: storage.k8s.io/v1beta1
|
||||||
|
@ -533,7 +533,7 @@ sh-4.2$ mysql -u $MYSQL_USER -p$MYSQL_PASSWORD -h $HOSTNAME $MYSQL_DATABASE
|
||||||
|
|
||||||
这点很方便,所有重要的配置,如MySQL凭据,数据库名称等都是pod模板中的环境变量的一部分,因此可以在pod中作为shell的环境变量。 我们来创建一些数据:
|
这点很方便,所有重要的配置,如MySQL凭据,数据库名称等都是pod模板中的环境变量的一部分,因此可以在pod中作为shell的环境变量。 我们来创建一些数据:
|
||||||
|
|
||||||
```Bash
|
```bash
|
||||||
mysql> show databases;
|
mysql> show databases;
|
||||||
+--------------------+
|
+--------------------+
|
||||||
| Database |
|
| Database |
|
||||||
|
|
|
@ -33,7 +33,7 @@ $ systemctl status glusterd.service
|
||||||
|
|
||||||
## 配置 glusterfs
|
## 配置 glusterfs
|
||||||
|
|
||||||
```Bash
|
```bash
|
||||||
# 配置 hosts
|
# 配置 hosts
|
||||||
|
|
||||||
$ vi /etc/hosts
|
$ vi /etc/hosts
|
||||||
|
@ -268,7 +268,7 @@ PVC属性
|
||||||
|
|
||||||
## 配置PVC
|
## 配置PVC
|
||||||
|
|
||||||
```Bash
|
```bash
|
||||||
$ cat glusterfs-pvc.yaml
|
$ cat glusterfs-pvc.yaml
|
||||||
kind: PersistentVolumeClaim
|
kind: PersistentVolumeClaim
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
|
@ -293,7 +293,7 @@ glusterfs-nginx Bound gluster-dev-volume 8Gi RWX
|
||||||
|
|
||||||
## 创建 nginx deployment 挂载 volume
|
## 创建 nginx deployment 挂载 volume
|
||||||
|
|
||||||
```Bash
|
```bash
|
||||||
$ vi nginx-deployment.yaml
|
$ vi nginx-deployment.yaml
|
||||||
apiVersion: extensions/v1beta1
|
apiVersion: extensions/v1beta1
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
|
|
Loading…
Reference in New Issue