Building Kubernetes - linux-on-ibm-z/docs GitHub Wiki

Building Kubernetes

Note: These instructions are no longer maintained. Please refer here for latest information.

The instructions provided below specify the steps to build Kubernetes version v1.5.7 on Linux on IBM Z for the following distributions:

  • RHEL (7.1, 7.2, 7.3)
  • SLES (12, 12 SP1, 12 SP2)
  • Ubuntu (16.04, 16.10)

General Notes:

  • When following the steps below please use a standard permission user unless otherwise specified.
  • A directory /<source_root>/ will be referred to in these instructions, this is a temporary writable directory anywhere you'd like to place it.

Prerequisites:

  • Go (Refer Go recipe)
  • Docker (For RHEL only)(Refer instructions mentioned here)

Step 1: Building Kubernetes

1.1) Install following dependencies

  • RHEL (7.1, 7.2, 7.3)

    sudo yum install git gcc-c++ which iptables make 
  • SLES (12, 12 SP1, 12 SP2)

    sudo zypper install git gcc-c++ which iptables make docker
  • Ubuntu (16.04, 16.10)

    sudo apt-get update
    sudo apt-get install git make iptables gcc wget tar flex subversion binutils-dev bzip2 build-essential vim docker

1.2) Set environment variables

export GOPATH=/<source_root>/kubernetes
export PATH=$PATH:$GOPATH/bin:$GOPATH/_output/local/go/bin

1.3) Clone the source code and replace sys package

cd /<source_root>/
git clone https://github.com/kubernetes/kubernetes.git
cd /<source_root>/kubernetes
git checkout v1.5.7
cd /<source_root>/kubernetes/vendor/golang.org/x
mv sys sys.bak
git clone https://github.com/linux-on-ibm-z/sys.git

1.4) Build Kubernetes

cd /<source_root>/kubernetes
make

Note: Execute the following commands if you get the error message cannot touch '_output/bin/deepcopy-gen': No such file or directory.

mkdir -p _output/bin
touch _output/bin/deepcopy-gen
touch _output/bin/conversion-gen
touch _output/bin/defaulter-gen
touch _output/bin/openapi-gen
chmod u=rwx _output/bin/deepcopy-gen
chmod u=rwx _output/bin/conversion-gen
chmod u=rwx _output/bin/defaulter-gen
chmod u=rwx _output/bin/openapi-gen

Step 2: Run test suites (Optional)

cd /<source_root>/kubernetes
make test

Note:

  • k8s.io/kubernetes/plugin/pkg/scheduler/algorithm/priorities test may fail on low-memory systems due to timeout.

Step 3: Running Kubernetes on a single host machine

Note: Please use root user to run services.

3.1) Set environment variables

export ETCD_UNSUPPORTED_ARCH=s390x
export KUBE_ENABLE_CLUSTER_DNS=true
export PATH=$PATH:/<source_root>/kubernetes/_output/local/go/bin

3.2) Install etcd

Instructions for building etcd can be found here. Make sure etcd binary is available in PATH environment variable.

3.3) Create single node Kubernetes cluster

cd /<source_root>/kubernetes
mkdir -p _output/local/bin/linux/s390x/
cp _output/local/go/bin/hyperkube _output/local/bin/linux/s390x/
cp _output/local/go/bin/kubectl _output/local/bin/linux/s390x/
cd /<source_root>/kubernetes/hack
./local-up-cluster.sh 

After running the above script, there will be some commands that you will have to run in another terminal to use the newly setup Kubernetes cluster. These commands will be displayed after running the script. Use the kubectl instead of cluster/kubectl.sh and run the commands as shown below:

kubectl config set-cluster local --server=https://<API_HOST>:<API_SECURE_PORT> --certificate-authority=<ROOT_CA_FILE>
kubectl config set-credentials myself --username=admin --password=admin
kubectl config set-context local --cluster=local --user=myself
kubectl config use-context local

Step 4: Deploy kube-dns and dnsmasq add-on (Optional)

Note: This recipe uses s390x docker images available for kube-dns and dnsmasq viz. gcr.io/google_containers/k8s-dns-kube-dns-s390x:1.14.1 and gcr.io/google_containers/k8s-dns-dnsmasq-s390x:1.14.1

4.1) Create dns-addon.yml file at /<source_root>/ location

apiVersion: v1
kind: Service
metadata:
  name: kube-dns
  namespace: kube-system
  labels:
    k8s-app: kube-dns
    kubernetes.io/cluster-service: "true"
    kubernetes.io/name: "KubeDNS"
spec:
  selector:
    k8s-app: kube-dns
  clusterIP: 10.0.0.10
  ports:
  - name: dns
    port: 53
    protocol: UDP
  - name: dns-tcp
    port: 53
    protocol: TCP

---

apiVersion: v1
kind: ReplicationController
metadata:
  name: kube-dns-v20
  namespace: kube-system
  labels:
    k8s-app: kube-dns
    version: v20
    kubernetes.io/cluster-service: "true"
spec:
  replicas: 1
  selector:
    k8s-app: kube-dns
    version: v20
  template:
    metadata:
      labels:
        k8s-app: kube-dns
        version: v20
      annotations:
        scheduler.alpha.kubernetes.io/critical-pod: ''
        scheduler.alpha.kubernetes.io/tolerations: '[{"key":"CriticalAddonsOnly", "operator":"Exists"}]'
    spec:
      containers:
      - name: kubedns
        image: gcr.io/google_containers/k8s-dns-kube-dns-s390x:1.14.1
        resources:
          limits:
            memory: 170Mi
          requests:
            cpu: 100m
            memory: 70Mi
        livenessProbe:
          httpGet:
            path: /healthz-kubedns
            port: 8080
            scheme: HTTP
          initialDelaySeconds: 60
          timeoutSeconds: 5
          successThreshold: 1
          failureThreshold: 5
        readinessProbe:
          httpGet:
            path: /readiness
            port: 8081
            scheme: HTTP
          initialDelaySeconds: 3
          timeoutSeconds: 5
        args:
        - --domain=cluster.local.
        - --dns-port=10053
        ports:
        - containerPort: 10053
          name: dns-local
          protocol: UDP
        - containerPort: 10053
          name: dns-tcp-local
          protocol: TCP
      - name: dnsmasq
        image: gcr.io/google_containers/k8s-dns-dnsmasq-s390x:1.14.1
        livenessProbe:
          httpGet:
            path: /healthz-dnsmasq
            port: 8080
            scheme: HTTP
          initialDelaySeconds: 60
          timeoutSeconds: 5
          successThreshold: 1
          failureThreshold: 5
        args:
        - --cache-size=1000
        - --no-resolv
        - --server=127.0.0.1#10053
        - --log-facility=-
        ports:
        - containerPort: 53
          name: dns
          protocol: UDP
        - containerPort: 53
          name: dns-tcp
          protocol: TCP
      - name: healthz
        image: gcr.io/google_containers/exechealthz-s390x:1.2
        resources:
          limits:
            memory: 50Mi
          requests:
            cpu: 10m
            memory: 50Mi
        args:
        - --cmd=nslookup kubernetes.default.svc.cluster.local 127.0.0.1 >/dev/null
        - --url=/healthz-dnsmasq
        - --cmd=nslookup kubernetes.default.svc.cluster.local 127.0.0.1:10053 >/dev/null
        - --url=/healthz-kubedns
        - --port=8080
        - --quiet
        ports:
        - containerPort: 8080
          protocol: TCP
      dnsPolicy: Default

4.2) Deploy kube-dns and dnsmasq

kubectl create -f /<source_root>/dns-addon.yml 

4.3) Verify kube-dns and dnsmasq pods are running

kubectl get pods -o wide -n kube-system

Output

NAME                 READY     STATUS    RESTARTS   AGE       IP           NODE
kube-dns-v20-*       2/2       Running   0          1m       <SOME-IP>   127.0.0.1

4.4) Create busybox.yaml file

apiVersion: v1
kind: Pod
metadata:
  name: busybox
  namespace: default
spec:
  containers:
  - image: s390x/busybox
    command:
      - sleep
      - "3600"
    imagePullPolicy: IfNotPresent
    name: busybox
  restartPolicy: Always

4.5) Deploy busybox pod and check its status

kubectl create -f /<source_root>/busybox.yaml
kubectl get pods 

Output

NAME      READY     STATUS    RESTARTS   AGE
busybox   1/1       Running   0          4m

4.6) Validate that DNS is working

kubectl exec -ti busybox -- nslookup kubernetes.default

Output

Server:    10.0.0.10
Address 1: 10.0.0.10 kube-dns.kube-system.svc.cluster.local

Name:      kubernetes.default
Address 1: 10.0.0.1 kubernetes.default.svc.cluster.local

If you see the above output that means DNS is working correctly. For more details please follow this link.

References:

http://kubernetes.io/

⚠️ **GitHub.com Fallback** ⚠️