Wednesday, March 24, 2021

Kubernetes - Practice notes

 Notes on Kubernetes
$ alias kc=kubectl


Day1 - Install minikube, VirtualBox

=================================================

Day2 - Practice
1. Create pod
> kc get pod
> kc run myweb --image=httpd
> kc get pods

2. Delete Pod
> kc get pods
> kc delete pod myweb-...
> kc get deployment
> kc expose deployments myweb --port=8080 --type=NodePort

> minikube service myweb --url
copy the URL and paste on browser.

2. Create deployment and expose it
> kc create deployment myweb2 --image=httpd
> kc expose deployment myweb2 --port=80 --type=NodePort
> minikube service myweb2 --url
> kc get pods
> kc get deployments
> kc scale deployment myweb2 --replicas=4

# docker ps
# docker run --name myweb -it web-server ....

=================================================

Day3 - practice
> minikube start
> minikube status

> kc get deployment
> kc delete all --all    # deletes everything

> kc run myos1 --image=httpd
> kc get pods
> kc describe pods myos1
> kc delete pods myos1

> notepad pod.yaml
apiVersion: v1
kind: Pod
metadata:
  name: "MyPod1"
spec:
  containers:
  - name: "MyC1"
    image: "httpd"

> kc create -f pod.yaml
> kc get pod
> kc get pods
> kc delete pods myos1
> minikube stop


some python eg,
name: "jay"

if
  x=1
  y=2

f=5

x=[ 1,2,3,4,5 ]
x:
- 1
- 2
- 3
- 4
- 5

> kc get pods
> kc describe pods myos1

kind

resources / keywords

type

$ docker ps | grep httpd

Google for api-server
kube-system

=================================================

Day4 - Practice
# docker images | grep httpd
# docker ps
# docker inspect os3

> kc get pods
> kc run webos1 --image=httpd
> kc get pods
> kc describe pods webos1
> kc get pods
> kc expose pod webos1 --port=80 --type=NodePort
> kc get services
> kc get rc

> notepad rc.yaml
apiVersion: v1
kind: ReplicationController
metadata:
  name: myrc1
spec:
  replicas: 5
  lecector:
    app:web
  template:
    metadata:
      name: "mypod"
    spec:
      containers:
      - name: "myc1"
        image: "httpd"

> kc create -f rc.yaml
> kc get rc
> kc get pods -L app
> kc delete mypod mypod1
> kc get pods
> kc describe rc myrc1
loog at under the message (events)


# docker run -it --name os3 httpd
# docker run -it --name os4 -p 1234/80 httpd

> curl http://192.168.99.100:31896

=================================================

Day5 - Practice
> kc get services
> kc get svc
> notepad svc.yaml
apiVersion: v1
kind: Service
metadata:
  name: my1b1
spec:
  selector:
    app: web
  ports:
    --targetPort: 80
      port: 8080
      nodePort: 30300
> kc apply -f svc.yaml
> kc get svc
> kc get pods
> kc describe svc my1b1

> curl http://192.168.99.100:30000
> kc get svc
> kc describe svc my1b1
Look for NodePort port

=================================================

Day6 - Practice
> kc run mydb --key=mysql:5.7
> kc get pods
> kc get pods
> kc logs mydb
> kc run myos1 --image=https

> kc get pods
> kc exec -it myos1 bash
# x=5
# echo $x
# exit
> kc exec -it myos1 -- bash
# echo $x
no value returned
# vi /root/.bashrc
x=5
alias rm='rm -i'

# echo $x
5
# exit
> kc exec -it myos1 -- bash
> kc exec -it myos1
> kc delete pod myos1

> kc run myos1 --image=httpd --env=x=10
> kc get pods
> kc exec -it myos1 -- bash
# echo $x
you see the value of x which is 10.
# exit

> kc delete all --all
> kc ge tpods
> kc run mydb --image=mysql:5.7 --env=MYSQL_ROOT_PASSWOD=redhat --env=MYSQL_DATABASE=wpdb --env=MYSQL_USER=jay --env=MYSQL_PASSWORD=redhat
> kc get pod
> kc logs mydb

> kc exec -it webdb -- bash
# mysql -u jay -predhat
mysql> show database
mysql> exit

> kc run myqp1 --image=wordpress:5.1.1-php7.3-apache
> kc get pods
> kc get svc
> kc expose pod mywp1 --type=NodePort --port=80
> kc get svc

get the nodeIP and the port
port is the output from svc command .
get the port info from port column.

http://192.168.10.20:30690

> kc exec -it mydn -- bash
# mysql -i jay -predhat
mysql> use wpdb;
mysql> show tables;

=================================================

Day7 - Practice
> notepad s.yaml
apiVersion: v1
kind: Secret
metadata:
  name: mysecret

data:
  p: cmVkaGF0
  u: jay
  up: redhat


> notepad s.yaml
apiVersion: v1
kind: Secret
metadata:
  name: mysecret
data:
  p: cmVkaGF0
  u: jay
  up: redhat123


> kc create -f s.yaml
> kc get secrets
> kc describe secrets mysecret
> kc get secrets
> kc get secret mysecret -o yaml

> kc create secret generic mys --from-literal=redhat
> kc get secrets

> notepad pod.yaml
apiVersion: v1
kind: Pod
metadata:
  name: "mydb"
  labels:
    app: mydb
spec:
  containers:
  - name: "mydb"
    image: "mysql:5.7"
    env:
    - name: MYSQL_ROOT_PASSWD
      valueFrom:
        secretKeyRef:
          name: mysecret
          key: p
    - name: MYSQL_USER
      valueFrom:
        secretKeyRef:
          name: mysecret
          key: u
    - name: MYSQL_PASS
      valueFrom:
        secretKeyRef:
          name: mysecret
          key: up
    - name: MYSQL_DATABASE
      value: wpdb



> kc create secret mysec


=================================================

Day8 - Practice

=================================================

Day9 - Practice

=================================================

Day10 - Practice

=================================================

Day11 - Practice





No comments:

Post a Comment

Git branch show detached HEAD

  Git branch show detached HEAD 1. List your branch $ git branch * (HEAD detached at f219e03)   00 2. Run re-set hard $ git reset --hard 3. ...