百家娱乐app博马网上娱乐

软考资料 / 2018年10月08日 06:27

电玩游戏厅万博赌博为什么不封

本文运用自己运用VirtubalBox建立的集群环境,暂时只要一个Master、一个Node。假如想了解集群的建立,能够参阅我的文章离线环境装置Kubernetes集群以及运用kubeadm装置kubernetes V1.11.1 集群。

0. 方针

在指令行下运用 kubectl 指令创立并办理布置。

1. 检查环境

检查本地的环境信息。

[[email protected] ~]# kubectl get nodes

NAME STATUS ROLES AGE VERSION

devops-101 Ready master 7h v1.11.1

devops-102 Ready

6h v1.11.1

2. 指令行方法创立布置

创立Tomcat布置,设置两个副本。

$ kubectl run docker.io/tomcat --replicas=2 --labels="app=tomcat" --image=docker.io/tomcat --port=8080

deployment.apps/tomcat created

[[email protected] ~]# kubectl get deployment

NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE

tomcat 2 2 2 2 6m

[[email protected] ~]# kubectl get pods

NAME READY STATUS RESTARTS AGE

tomcat-858b8c476d-vnm98 1/1 Running 0 6m

tomcat-858b8c476d-xl5xl 1/1 Running 0 6m

创立布置之后,能够看到容器现已运行了,可是默许情况下,容器只能内部相互拜访,假如需求对外供给效劳,有以下几种方法:

ClusterIP,默许的方法,经过集群IP来对外供给效劳,这种方法只能在集群内部拜访。

NodePort,运用NAT技能在Node的指定端口上供给对外效劳。外部运用经过:的方法拜访。

LoadBalancer,运用外部的负载均衡设备进行效劳的拜访。

ExternalName,这是1.7版别之后 kube-dns 供给的功用。

2.1 端口映射,向外部露出效劳

在Kubernetes中Pod有其自己的生命周期,Node发作毛病时,ReplicationController或许ReplicationSet会将Pod迁移到其他节点中以坚持用户期望的状况。

[[email protected] ~]# kubectl expose deployment/tomcat --type="NodePort" --port 8080

service/tomcat exposed

检查service被映射到哪个端口。

[[email protected] ~]# kubectl get service

NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE

kubernetes ClusterIP 10.96.0.1

443/TCP 8h

tomcat NodePort 10.98.152.28

8080:32050/TCP 7s

由于知道被调度到了102节点,手艺经过浏览器翻开 https://192.168.0.102:32050 检查效劳是否能够正常拜访。

3. 根据YAML文件创立布置

首要修改Yaml文件

apiVersion: v1

kind: Pod

metadata: #元数据信息

name: tomcat-c #kubectl get pods 和 登陆容器显现的姓名

labels: #标签,能够作为查询条件 kubectl get pods -l

app=tomcat

node=devops-103

spec: #标准

containers: #容器

- name: tomcat #容器称号

image: docker.io/tomcat #运用的镜像

ports:

- containerPort: 8080

env: #设置env,登陆到容器中检查环境变量, DEME_GREETING 的值是 "hello from the enviroment"

- name:GREETING

value: "hello from the environment"

然后创立Pod。

[[email protected] ~]# kubectl create -f tomcat.yaml

pod/tomcat-ccb created

[[email protected] ~]# kubectl get pods

NAME READY STATUS RESTARTS AGE

tomcat-858b8c476d-vnm98 1/1 Running 2 21h

tomcat-858b8c476d-xl5xl 1/1 Running 3 21h

tomcat-ccb 1/1 Running 0 34s

4. 扩容布置

在扩容之前,我把devops-102节点也加入到集群中。

[[email protected] ~]# kubectl get nodes

NAME STATUS ROLES AGE VERSION

devops-101 Ready master 9h v1.11.1

devops-102 Ready

8h v1.11.1

devops-103 Ready

7h v1.11.1

然后再履行扩容动作。

[[email protected] ~]# kubectl scale deployments/tomcat --replicas=3

deployment.extensions/tomcat scaled

[[email protected] ~]# kubectl get deployments

NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE

tomcat 3 3 3 2 1h

[[email protected] ~]# kubectl get pods

NAME READY STATUS RESTARTS AGE

tomcat-858b8c476d-cfrtt 0/1 ContainerCreating 0 2m

tomcat-858b8c476d-vnm98 1/1 Running 0 1h

tomcat-858b8c476d-xl5xl 1/1 Running 0 1h

[[email protected] ~]# kubectl describe pod tomcat-858b8c476d-cfrtt

Name: tomcat-858b8c476d-cfrtt

Namespace: default

Node: devops-103/192.168.0.103

Start Time: Tue, 24 Jul 2018 18:29:51 +0800

Labels: app=tomcat

pod-template-hash=4146470328

Annotations:

Status: Pending

IP:

Controlled By: ReplicaSet/tomcat-858b8c476d

Containers:

tomcat:

Container ID:

Image: docker.io/tomcat

Image ID:

Port: 8080/TCP

Host Port: 0/TCP

State: Waiting

Reason: ContainerCreating

Ready: False

Restart Count: 0

Environment:

Mounts:

/var/run/secrets/kubernetes.io/serviceaccount from default-token-trvqv (ro)

Conditions:

Type Status

Initialized True

Ready False

ContainersReady False

PodScheduled True

Volumes:

default-token-trvqv:

Type: Secret (a volume populated by a Secret)

SecretName: default-token-trvqv

Optional: false

QoS Class: BestEffort

Node-Selectors:

Tolerations: node.kubernetes.io/not-ready:NoExecute for 300s

node.kubernetes.io/unreachable:NoExecute for 300s

Events:

Type Reason Age From Message

---- ------ ---- ---- -------

Normal Scheduled 2m default-scheduler Successfully assigned default/tomcat-858b8c476d-cfrtt to devops-103

Normal Pulling

kubelet, devops-103 pulling image "docker.io/tomcat"

5. 缩容

[[email protected] ~]# kubectl scale deployments/tomcat --replicas=2

deployment.extensions/tomcat scaled

[[email protected] ~]# kubectl get pods

NAME READY STATUS RESTARTS AGE

tomcat-858b8c476d-vnm98 1/1 Running 0 1h

tomcat-858b8c476d-xl5xl 1/1 Running 0 1h

6. 标签功用

创立布置的时分,kubectl会主动帮咱们打一个标签,这儿是app=tomcat。

[[email protected] ~]# kubectl describe deployment

Name: tomcat

Namespace: default

CreationTimestamp: Tue, 24 Jul 2018 16:35:08 +0800

Labels: app=tomcat

Annotations: deployment.kubernetes.io/revision=1

Selector: app=tomcat

Replicas: 2 desired | 2 updated | 2 total | 2 available | 0 unavailable

StrategyType: RollingUpdate

MinReadySeconds: 0

RollingUpdateStrategy: 25% max unavailable, 25% max surge

Pod Template:

Labels: app=tomcat

Containers:

tomcat:

Image: docker.io/tomcat

Port: 8080/TCP

Host Port: 0/TCP

Environment:

Mounts:

Volumes:

Conditions:

Type Status Reason

---- ------ ------

Progressing True NewReplicaSetAvailable

Available True MinimumReplicasAvailable

OldReplicaSets:

NewReplicaSet: tomcat-858b8c476d (2/2 replicas created)

Events:

Type Reason Age From Message

---- ------ ---- ---- -------

Normal ScalingReplicaSet 18m deployment-controller Scaled up replica set tomcat-858b8c476d to 3

Normal ScalingReplicaSet 4m deployment-controller Scaled down replica set tomcat-858b8c476d to 2

能够运用标签来查询资源,包含Pods和Services。

[[email protected] ~]# kubectl get pods -l app=tomcat

NAME READY STATUS RESTARTS AGE

tomcat-858b8c476d-vnm98 1/1 Running 0 1h

tomcat-858b8c476d-xl5xl 1/1 Running 0 1h

[[email protected] ~]# kubectl get services -l app=tomcat

NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE

tomcat NodePort 10.98.152.28

8080:32050/TCP 1h

能够给Pods打上自定义的标签。[[email protected] ~]# kubectl label --overwrite pod tomcat-858b8c476d-vnm98 node=devops-102

# 这儿用了--overwrite特点是由于之前标错了

[[email protected] ~]# kubectl describe pods tomcat-858b8c476d-vnm98

Name: tomcat-858b8c476d-vnm98

Namespace: default

Node: devops-102/192.168.0.102

Start Time: Tue, 24 Jul 2018 16:35:08 +0800

Labels: app=tomcat

node=devops-102

pod-template-hash=4146470328

Annotations:

Status: Running

IP: 10.244.2.6

Controlled By: ReplicaSet/tomcat-858b8c476d

Containers:

tomcat:

Container ID: docker://9f3aa2d3d6c1937d4209a44820c1cd06f7eaf8796848c759e19410358aea4866

Image: docker.io/tomcat

Image ID: docker-pullable://docker.io/[email protected]:87ad70ceaafd5c71301b081b37ca2795bd6c7c1a5599a8c92c9447bbd225ae47

Port: 8080/TCP

Host Port: 0/TCP

State: Running

Started: Tue, 24 Jul 2018 16:35:37 +0800

Ready: True

Restart Count: 0

Environment:

Mounts:

/var/run/secrets/kubernetes.io/serviceaccount from default-token-trvqv (ro)

Conditions:

Type Status

Initialized True

Ready True

ContainersReady True

PodScheduled True

Volumes:

default-token-trvqv:

Type: Secret (a volume populated by a Secret)

SecretName: default-token-trvqv

Optional: false

QoS Class: BestEffort

Node-Selectors:

Tolerations: node.kubernetes.io/not-ready:NoExecute for 300s

node.kubernetes.io/unreachable:NoExecute for 300s

Events:

7. 删去布置$ kubectl delete pod-name

1. 188bet体育遵循行业规范,任何转载的稿件都会明确标注作者和来源;2. 188bet体育的原创文章,请转载时务必注明文章作者和"来源: 188bet体育",不尊重原创的行为 188bet体育或将追究责任;3.作者投稿可能会经 188bet体育编辑修改或补充。